Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,25 +1,33 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
|
| 3 |
|
| 4 |
-
#
|
| 5 |
-
|
| 6 |
-
tokenizer_name = "t5-small"
|
| 7 |
-
|
| 8 |
-
tokenizer = AutoTokenizer.from_pretrained(tokenizer_name)
|
| 9 |
-
model = AutoModelForSeq2SeqLM.from_pretrained(model_name)
|
| 10 |
|
| 11 |
def generate_response(message):
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
|
|
|
|
| 16 |
iface = gr.Interface(
|
| 17 |
fn=generate_response,
|
| 18 |
inputs=gr.Textbox(placeholder="Type your message here...", label="Message"),
|
| 19 |
outputs="text",
|
| 20 |
-
title="Real-Time Chatbot with
|
| 21 |
-
description="Ask any question or start a conversation.",
|
| 22 |
-
theme="dark", # Optional: Use a dark theme
|
| 23 |
)
|
| 24 |
|
| 25 |
-
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
import openai
|
| 3 |
|
| 4 |
+
# Set your OpenAI API key here
|
| 5 |
+
openai.api_key = "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" # Replace with your actual API key
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
|
| 7 |
def generate_response(message):
|
| 8 |
+
try:
|
| 9 |
+
response = openai.Completion.create(
|
| 10 |
+
engine="text-davinci-003", # Adjust model as needed
|
| 11 |
+
prompt=f"Question: {message}",
|
| 12 |
+
max_tokens=150,
|
| 13 |
+
n=1,
|
| 14 |
+
stop=None, # No explicit stop sequences for chat-like interactions
|
| 15 |
+
temperature=0.7,
|
| 16 |
+
)
|
| 17 |
+
# Return the content of the response
|
| 18 |
+
return response.choices[0].text.strip()
|
| 19 |
+
except Exception as e:
|
| 20 |
+
return f"Error: {str(e)}"
|
| 21 |
|
| 22 |
+
# Create the Gradio interface
|
| 23 |
iface = gr.Interface(
|
| 24 |
fn=generate_response,
|
| 25 |
inputs=gr.Textbox(placeholder="Type your message here...", label="Message"),
|
| 26 |
outputs="text",
|
| 27 |
+
title="Real-Time Chatbot with GPT-3.5",
|
| 28 |
+
description="Ask any question or start a conversation. Powered by OpenAI GPT-3.5-turbo.",
|
| 29 |
+
theme="dark", # Optional: Use a dark theme for a more modern look
|
| 30 |
)
|
| 31 |
|
| 32 |
+
# Launch the interface
|
| 33 |
+
iface.launch()
|