Spaces:
Runtime error
Runtime error
Commit
Β·
8fccea5
1
Parent(s):
e5abfa3
Update app.py
Browse files
app.py
CHANGED
@@ -13,6 +13,26 @@ def sentiment_analysis(text):
|
|
13 |
result = pipe(text)
|
14 |
return result
|
15 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
16 |
|
17 |
with gr.Blocks() as demo:
|
18 |
gr.Markdown("Choose the Chinese NLP model you want to use.")
|
@@ -20,5 +40,10 @@ with gr.Blocks() as demo:
|
|
20 |
text_button = gr.Button("proceed")
|
21 |
text_button.click(fn=sentiment_analysis,inputs=gr.Textbox(placeholder="Enter a positive or negative sentence here..."),
|
22 |
outputs=gr.Textbox(label="Sentiment Analysis"))
|
|
|
|
|
|
|
|
|
|
|
23 |
|
24 |
demo.launch(inline=False)
|
|
|
13 |
result = pipe(text)
|
14 |
return result
|
15 |
|
16 |
+
def openai_chatbot(prompt):
|
17 |
+
# Set up the OpenAI API client
|
18 |
+
openai.api_key = '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'
|
19 |
+
|
20 |
+
# Set up the model and prompt
|
21 |
+
model_engine = "text-davinci-003"
|
22 |
+
|
23 |
+
# Generate a response
|
24 |
+
completion = openai.Completion.create(
|
25 |
+
engine=model_engine,
|
26 |
+
prompt=prompt,
|
27 |
+
max_tokens=1024,
|
28 |
+
n=1,
|
29 |
+
stop=None,
|
30 |
+
temperature=0.5,
|
31 |
+
)
|
32 |
+
|
33 |
+
response = completion.choices[0].text
|
34 |
+
|
35 |
+
return f'π€ {response}'
|
36 |
|
37 |
with gr.Blocks() as demo:
|
38 |
gr.Markdown("Choose the Chinese NLP model you want to use.")
|
|
|
40 |
text_button = gr.Button("proceed")
|
41 |
text_button.click(fn=sentiment_analysis,inputs=gr.Textbox(placeholder="Enter a positive or negative sentence here..."),
|
42 |
outputs=gr.Textbox(label="Sentiment Analysis"))
|
43 |
+
with gr.Tab("General Chatbot"):
|
44 |
+
text_button = gr.Button("proceed")
|
45 |
+
text_button.click(fn=openai_chatbot,inputs=gr.Textbox(placeholder="Enter any topic you would like to discuss in Chinese"),
|
46 |
+
outputs=gr.Textbox(label="Chatbot Response"))
|
47 |
+
|
48 |
|
49 |
demo.launch(inline=False)
|