Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -11,33 +11,12 @@ from helpers.foundation_models import *
|
|
11 |
import requests
|
12 |
|
13 |
|
|
|
14 |
OPENAI_API_KEY = os.environ["OPENAI_API_KEY"]
|
15 |
SERPAPI_API_KEY = os.environ["SERPAPI_API_KEY"]
|
16 |
openai_client = openai.OpenAI(api_key=OPENAI_API_KEY)
|
17 |
|
18 |
|
19 |
-
API_URL = "https://sks7h7h5qkhoxwxo.us-east-1.aws.endpoints.huggingface.cloud"
|
20 |
-
headers = {
|
21 |
-
"Accept" : "application/json",
|
22 |
-
"Content-Type": "application/json"
|
23 |
-
}
|
24 |
-
|
25 |
-
|
26 |
-
def query(payload):
|
27 |
-
response = requests.post(API_URL, headers=headers, json=payload)
|
28 |
-
return response.json()
|
29 |
-
|
30 |
-
|
31 |
-
def llama2_7b_ysa(prompt: str) -> str:
|
32 |
-
output = query({
|
33 |
-
"inputs": prompt,
|
34 |
-
"parameters": {}
|
35 |
-
})
|
36 |
-
|
37 |
-
response = output[0]['generated_text']
|
38 |
-
|
39 |
-
return response
|
40 |
-
|
41 |
# Initialize chat history
|
42 |
if "messages" not in st.session_state:
|
43 |
st.session_state.messages = []
|
@@ -49,6 +28,7 @@ for message in st.session_state.messages:
|
|
49 |
st.markdown(message["content"])
|
50 |
|
51 |
|
|
|
52 |
with st.expander("Instructions"):
|
53 |
st.sidebar.markdown(
|
54 |
r"""
|
@@ -68,9 +48,7 @@ option = st.sidebar.selectbox(
|
|
68 |
|
69 |
|
70 |
clear_button = st.sidebar.button("Clear Conversation", key="clear")
|
71 |
-
|
72 |
st.sidebar.write("---")
|
73 |
-
|
74 |
st.sidebar.markdown("Yiqiao Yin: [Site](https://www.y-yin.io/) | [LinkedIn](https://www.linkedin.com/in/yiqiaoyin/)")
|
75 |
|
76 |
|
@@ -81,11 +59,14 @@ if clear_button:
|
|
81 |
|
82 |
# React to user input
|
83 |
if prompt := st.chat_input("What is up?"):
|
|
|
84 |
# Display user message in chat message container
|
85 |
st.chat_message("user").markdown(prompt)
|
|
|
86 |
# Add user message to chat history
|
87 |
st.session_state.messages.append({"role": "user", "content": prompt})
|
88 |
|
|
|
89 |
with st.spinner("Wait for it..."):
|
90 |
if option == "Sentiment Analysis":
|
91 |
pipe_sentiment_analysis = pipeline("sentiment-analysis")
|
|
|
11 |
import requests
|
12 |
|
13 |
|
14 |
+
# API Keys
|
15 |
OPENAI_API_KEY = os.environ["OPENAI_API_KEY"]
|
16 |
SERPAPI_API_KEY = os.environ["SERPAPI_API_KEY"]
|
17 |
openai_client = openai.OpenAI(api_key=OPENAI_API_KEY)
|
18 |
|
19 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
# Initialize chat history
|
21 |
if "messages" not in st.session_state:
|
22 |
st.session_state.messages = []
|
|
|
28 |
st.markdown(message["content"])
|
29 |
|
30 |
|
31 |
+
# Sidebar
|
32 |
with st.expander("Instructions"):
|
33 |
st.sidebar.markdown(
|
34 |
r"""
|
|
|
48 |
|
49 |
|
50 |
clear_button = st.sidebar.button("Clear Conversation", key="clear")
|
|
|
51 |
st.sidebar.write("---")
|
|
|
52 |
st.sidebar.markdown("Yiqiao Yin: [Site](https://www.y-yin.io/) | [LinkedIn](https://www.linkedin.com/in/yiqiaoyin/)")
|
53 |
|
54 |
|
|
|
59 |
|
60 |
# React to user input
|
61 |
if prompt := st.chat_input("What is up?"):
|
62 |
+
|
63 |
# Display user message in chat message container
|
64 |
st.chat_message("user").markdown(prompt)
|
65 |
+
|
66 |
# Add user message to chat history
|
67 |
st.session_state.messages.append({"role": "user", "content": prompt})
|
68 |
|
69 |
+
# Execute options
|
70 |
with st.spinner("Wait for it..."):
|
71 |
if option == "Sentiment Analysis":
|
72 |
pipe_sentiment_analysis = pipeline("sentiment-analysis")
|