Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import gradio as gr
|
| 3 |
+
from openai import OpenAI
|
| 4 |
+
|
| 5 |
+
# Load API key from Hugging Face Secrets
|
| 6 |
+
# (set OPENAI_API_KEY in your Space settings)
|
| 7 |
+
client = OpenAI(api_key=os.environ["OPENAI_API_KEY"])
|
| 8 |
+
|
| 9 |
+
# Function to ask the app
|
| 10 |
+
def ask_app(question):
|
| 11 |
+
try:
|
| 12 |
+
response = client.responses.create(
|
| 13 |
+
prompt={
|
| 14 |
+
"id": "pmpt_69f610df1d70819683a15d371bd47ca00b92de12291fced1",
|
| 15 |
+
"version": "1"
|
| 16 |
+
},
|
| 17 |
+
input=question,
|
| 18 |
+
reasoning={"summary": "auto"}
|
| 19 |
+
)
|
| 20 |
+
return response.output_text
|
| 21 |
+
except Exception as e:
|
| 22 |
+
return f"Error: {str(e)}"
|
| 23 |
+
|
| 24 |
+
# Gradio interface
|
| 25 |
+
demo = gr.Interface(
|
| 26 |
+
fn=ask_app,
|
| 27 |
+
inputs=gr.Textbox(
|
| 28 |
+
lines=3,
|
| 29 |
+
placeholder="Type your question here...",
|
| 30 |
+
label="Your Question"
|
| 31 |
+
),
|
| 32 |
+
outputs=gr.Textbox(
|
| 33 |
+
lines=10,
|
| 34 |
+
label="Answer"
|
| 35 |
+
),
|
| 36 |
+
title="DDS Cohort 10 2nd App Python Research Bot",
|
| 37 |
+
description="Ask a question and get answers from your saved prompt + vector store."
|
| 38 |
+
)
|
| 39 |
+
|
| 40 |
+
# Launch app
|
| 41 |
+
demo.launch(share=True)
|