Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import openai
|
3 |
+
import os
|
4 |
+
|
5 |
+
#from google.colab import userdata
|
6 |
+
#OPENAI_API_KEY = userdata.get('OPENAI_API_KEY')
|
7 |
+
|
8 |
+
# Fetch OpenAI API Key from Hugging Face Secrets
|
9 |
+
OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")
|
10 |
+
|
11 |
+
def chatbot(prompt):
|
12 |
+
""" GPT-4o Mini Chatbot """
|
13 |
+
openai.api_key = OPENAI_API_KEY
|
14 |
+
response = openai.ChatCompletion.create(
|
15 |
+
model="gpt-4o-mini",
|
16 |
+
messages=[{"role": "system", "content": "You are a helpful assistant."},
|
17 |
+
{"role": "user", "content": prompt}]
|
18 |
+
)
|
19 |
+
return response['choices'][0]['message']['content']
|
20 |
+
|
21 |
+
# Create Gradio UI
|
22 |
+
app = gr.Interface(fn=chatbot, inputs="text", outputs="text", title="GPT-4o Mini Chatbot")
|
23 |
+
|
24 |
+
# Run the chatbot
|
25 |
+
app.launch(debug=True)
|