Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -6,44 +6,41 @@ import os
|
|
6 |
TOGETHER_API_KEY = os.getenv('TOGETHER_API_KEY')
|
7 |
|
8 |
# Streamlit UI
|
9 |
-
st.title("
|
10 |
|
11 |
-
# User input for
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
Sentence: I can say that there isn't anything I would change.
|
16 |
-
Label: positive
|
17 |
-
|
18 |
-
Sentence: I'm not sure about this.
|
19 |
-
Sentence: neutral
|
20 |
-
|
21 |
-
Sentence: I liked some parts but I didn't like other parts.
|
22 |
-
Label: mixed
|
23 |
-
|
24 |
-
Sentence: I think the background image could have been better.
|
25 |
-
Label: negative
|
26 |
-
|
27 |
-
Sentence: I really like it.
|
28 |
-
Label:""")
|
29 |
|
30 |
# Together API endpoint
|
31 |
-
endpoint = 'https://api.together.xyz/inference'
|
32 |
-
|
33 |
-
#
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
"
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
TOGETHER_API_KEY = os.getenv('TOGETHER_API_KEY')
|
7 |
|
8 |
# Streamlit UI
|
9 |
+
st.title("Movie Review Sentiment Analysis")
|
10 |
|
11 |
+
# User input for movie review
|
12 |
+
zero_shot_prompt = st.text_area("Enter zero-shot prompt:", "")
|
13 |
+
one_shot_prompt = st.text_area("Enter one-shot prompt:", "")
|
14 |
+
few_shot_prompt = st.text_area("Enter few-shot prompt (comma-separated options):", "")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
|
16 |
# Together API endpoint
|
17 |
+
endpoint = 'https://api.together.xyz/inference'
|
18 |
+
|
19 |
+
# Determine the prompt based on user input
|
20 |
+
if st.button("Analyze Zero-shot"):
|
21 |
+
prompt = zero_shot_prompt
|
22 |
+
elif st.button("Analyze One-shot"):
|
23 |
+
prompt = one_shot_prompt
|
24 |
+
elif st.button("Analyze Few-shot"):
|
25 |
+
prompt_options = few_shot_prompt.split(',')
|
26 |
+
prompt = '\n'.join([f"Option {i + 1}: {option.strip()}" for i, option in enumerate(prompt_options)])
|
27 |
+
else:
|
28 |
+
prompt = ""
|
29 |
+
|
30 |
+
# Make a request to Together API if a prompt is provided
|
31 |
+
if prompt:
|
32 |
+
response = requests.post(endpoint, json={
|
33 |
+
"model": 'togethercomputer/RedPajama-INCITE-7B-Base',
|
34 |
+
"prompt": prompt,
|
35 |
+
"top_p": 1,
|
36 |
+
"top_k": 40,
|
37 |
+
"temperature": 0.8,
|
38 |
+
"max_tokens": 1,
|
39 |
+
"repetition_penalty": 1,
|
40 |
+
}, headers={
|
41 |
+
"Authorization": f"Bearer {TOGETHER_API_KEY}"
|
42 |
+
})
|
43 |
+
|
44 |
+
# Display the output
|
45 |
+
st.text("Sentiment Analysis Result:")
|
46 |
+
st.text(response.json()['output']['choices'][0]['text'])
|