Portfolio / app.py
Purnimajagann's picture
Update app.py
f296e45 verified
raw
history blame contribute delete
789 Bytes
import gradio as gr
import openai
import os
# Fetch OpenAI API Key from Hugging Face Secrets (NO .env file)
OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")
if OPENAI_API_KEY is None:
raise ValueError("ERROR: OpenAI API key not found! Make sure to set it in Hugging Face Secrets.")
def chatbot(prompt):
""" GPT-4o Mini Chatbot """
openai.api_key = OPENAI_API_KEY
response = openai.ChatCompletion.create(
model="gpt-4o-mini",
messages=[{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": prompt}]
)
return response['choices'][0]['message']['content']
# Create Gradio UI
app = gr.Interface(fn=chatbot, inputs="text", outputs="text", title="GPT-4o Mini Chatbot")
# Run the chatbot
app.launch()