VaibT's picture
Create app.py
ec9a5b6 verified
import os
import gradio as gr
from openai import OpenAI
# Load API key from Hugging Face Secrets
# (set OPENAI_API_KEY in your Space settings)
client = OpenAI(api_key=os.environ["OPENAI_API_KEY"])
# Function to ask the app
def ask_app(question):
try:
response = client.responses.create(
prompt={
"id": "pmpt_69f610df1d70819683a15d371bd47ca00b92de12291fced1",
"version": "1"
},
input=question,
reasoning={"summary": "auto"}
)
return response.output_text
except Exception as e:
return f"Error: {str(e)}"
# Gradio interface
demo = gr.Interface(
fn=ask_app,
inputs=gr.Textbox(
lines=3,
placeholder="Type your question here...",
label="Your Question"
),
outputs=gr.Textbox(
lines=10,
label="Answer"
),
title="DDS Cohort 10 2nd App Python Research Bot",
description="Ask a question and get answers from your saved prompt + vector store."
)
# Launch app
demo.launch(share=True)