Spaces:
Sleeping
Sleeping
Delete pages/Text_Generation.py
Browse files- pages/Text_Generation.py +0 -74
pages/Text_Generation.py
DELETED
@@ -1,74 +0,0 @@
|
|
1 |
-
import streamlit as st
|
2 |
-
from hugchat import hugchat
|
3 |
-
from hugchat.login import Login
|
4 |
-
import os
|
5 |
-
|
6 |
-
# App title
|
7 |
-
st.set_page_config(page_title="π€π¬ HugChat")
|
8 |
-
|
9 |
-
# Hugging Face Credentials
|
10 |
-
with st.sidebar:
|
11 |
-
st.title('π€π¬ HugChat')
|
12 |
-
if ('EMAIL' in st.secrets) and ('PASS' in st.secrets):
|
13 |
-
st.success('HuggingFace Login credentials already provided!', icon='β
')
|
14 |
-
hf_email = st.secrets['EMAIL']
|
15 |
-
hf_pass = st.secrets['PASS']
|
16 |
-
else:
|
17 |
-
hf_email = st.text_input('Enter E-mail:', type='password')
|
18 |
-
hf_pass = st.text_input('Enter password:', type='password')
|
19 |
-
if not (hf_email and hf_pass):
|
20 |
-
st.warning('Please enter your credentials!', icon='β οΈ')
|
21 |
-
else:
|
22 |
-
st.success('Proceed to entering your prompt message!', icon='π')
|
23 |
-
|
24 |
-
#sign = Login(hf_email, hf_pass)
|
25 |
-
#cookies = sign.login()
|
26 |
-
|
27 |
-
|
28 |
-
# Store LLM generated responses
|
29 |
-
if "messages" not in st.session_state:
|
30 |
-
st.session_state.messages = [{"role": "assistant", "content": "How may I assist you today?"}]
|
31 |
-
|
32 |
-
# Display or clear chat messages
|
33 |
-
for message in st.session_state.messages:
|
34 |
-
with st.chat_message(message["role"]):
|
35 |
-
st.write(message["content"])
|
36 |
-
|
37 |
-
def clear_chat_history():
|
38 |
-
st.session_state.messages = [{"role": "assistant", "content": "How may I assist you today?"}]
|
39 |
-
st.sidebar.button('Clear Chat History', on_click=clear_chat_history)
|
40 |
-
|
41 |
-
# Function for generating LLM response
|
42 |
-
def generate_response(prompt_input, email, passwd):
|
43 |
-
# Hugging Face Login
|
44 |
-
#sign = Login(email, passwd)
|
45 |
-
#cookies = sign.login()
|
46 |
-
|
47 |
-
# Create ChatBot
|
48 |
-
#chatbot = hugchat.ChatBot(cookies=cookies.get_dict())
|
49 |
-
#return chatbot.chat(prompt_input)
|
50 |
-
|
51 |
-
for dict_message in st.session_state.messages:
|
52 |
-
string_dialogue = "You are a helpful assistant."
|
53 |
-
if dict_message["role"] == "user":
|
54 |
-
string_dialogue += "User: " + dict_message["content"] + "\n\n"
|
55 |
-
else:
|
56 |
-
string_dialogue += "Assistant: " + dict_message["content"] + "\n\n"
|
57 |
-
|
58 |
-
prompt = f"{string_dialogue} {prompt_input} Assistant: "
|
59 |
-
#return chatbot.chat(prompt)
|
60 |
-
|
61 |
-
# User-provided prompt
|
62 |
-
if prompt := st.chat_input(disabled=not (hf_email and hf_pass)):
|
63 |
-
st.session_state.messages.append({"role": "user", "content": prompt})
|
64 |
-
with st.chat_message("user"):
|
65 |
-
st.write(prompt)
|
66 |
-
|
67 |
-
# Generate a new response if last message is not from assistant
|
68 |
-
if st.session_state.messages[-1]["role"] != "assistant":
|
69 |
-
with st.chat_message("assistant"):
|
70 |
-
with st.spinner("Thinking..."):
|
71 |
-
response = generate_response(prompt, hf_email, hf_pass)
|
72 |
-
st.write(response)
|
73 |
-
message = {"role": "assistant", "content": response}
|
74 |
-
st.session_state.messages.append(message)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|