Spaces:
Sleeping
Sleeping
Commit
·
90ba62d
1
Parent(s):
02caad9
- app.py +28 -0
- chatbot.app +0 -0
app.py
ADDED
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import openai
|
3 |
+
import os
|
4 |
+
|
5 |
+
# Set up OpenAI API key (use an environment variable for security)
|
6 |
+
openai.api_key = os.getenv("OPENAI_API_KEY")
|
7 |
+
|
8 |
+
def chat_with_ai(prompt):
|
9 |
+
"""Generates a response from OpenAI's GPT-3.5."""
|
10 |
+
try:
|
11 |
+
response = openai.ChatCompletion.create(
|
12 |
+
model="gpt-3.5-turbo",
|
13 |
+
messages=[{"role": "user", "content": prompt}]
|
14 |
+
)
|
15 |
+
return response["choices"][0]["message"]["content"]
|
16 |
+
except Exception as e:
|
17 |
+
return f"Error: {str(e)}"
|
18 |
+
|
19 |
+
# Create Gradio interface
|
20 |
+
iface = gr.Interface(
|
21 |
+
fn=chat_with_ai,
|
22 |
+
inputs=gr.Textbox(placeholder="Ask me anything..."),
|
23 |
+
outputs=gr.Textbox()
|
24 |
+
)
|
25 |
+
|
26 |
+
# Launch the app
|
27 |
+
if __name__ == "__main__":
|
28 |
+
iface.launch()
|
chatbot.app
DELETED
File without changes
|