Spaces:
Runtime error
Runtime error
tonygunawan
commited on
Commit
•
336dfd5
1
Parent(s):
794006d
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import openai
|
3 |
+
from openai import OpenAI
|
4 |
+
|
5 |
+
def query(prompt):
|
6 |
+
client = client = OpenAI(api_key = "...") # your own key
|
7 |
+
|
8 |
+
system_prompt = """
|
9 |
+
You are a helpful text sentiment classifier. Answer ONLY using these three options: ['Positive', 'Negative', 'Neutral']
|
10 |
+
"""
|
11 |
+
|
12 |
+
user_prompt = f"""
|
13 |
+
Classify the text into neutral, negative or positive.
|
14 |
+
Text: {prompt}
|
15 |
+
Sentiment:
|
16 |
+
"""
|
17 |
+
|
18 |
+
message = [{"role": "system", "content": f"{system_prompt}"},{"role": "user", "content": f"{user_prompt}"}]
|
19 |
+
|
20 |
+
response = client.chat.completions.create(
|
21 |
+
model="gpt-3.5-turbo-1106",
|
22 |
+
messages=message,
|
23 |
+
temperature=0.5
|
24 |
+
)
|
25 |
+
return response.choices[0].message.content
|
26 |
+
|
27 |
+
gr.Interface(fn=query, inputs="textbox", outputs="textbox").launch()
|