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