Spaces:
Runtime error
Runtime error
Commit
·
a380611
1
Parent(s):
a2adf87
Update app.py
Browse files
app.py
CHANGED
@@ -1 +1,29 @@
|
|
1 |
-
import
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import gradio as gr
|
3 |
+
import openai
|
4 |
+
|
5 |
+
def chatbot(prompt, api_key):
|
6 |
+
openai.api_key = api_key
|
7 |
+
response = openai.Completion.create(
|
8 |
+
engine="davinci",
|
9 |
+
prompt=prompt,
|
10 |
+
temperature=0.7,
|
11 |
+
max_tokens=1024,
|
12 |
+
top_p=1,
|
13 |
+
frequency_penalty=0,
|
14 |
+
presence_penalty=0
|
15 |
+
)
|
16 |
+
message = response.choices[0].text.strip()
|
17 |
+
return message
|
18 |
+
|
19 |
+
input_prompt = gr.inputs.Textbox(lines=7, label="Enter your message")
|
20 |
+
input_api_key = gr.inputs.Textbox(label="Enter your OpenAI API key")
|
21 |
+
|
22 |
+
output_text = gr.outputs.Textbox(label="Bot's reply")
|
23 |
+
|
24 |
+
title = "OpenAI Chatbot"
|
25 |
+
description = "An AI chatbot powered by OpenAI's GPT-3 language model."
|
26 |
+
examples = [["Hi there!", "Hello! How can I assist you today?"]]
|
27 |
+
iface = gr.Interface(fn=chatbot, inputs=[input_prompt, input_api_key], outputs=output_text, title=title, description=description, examples=examples)
|
28 |
+
|
29 |
+
iface.launch()
|