ajoyganguly commited on
Commit
e96092e
·
verified ·
1 Parent(s): c200a08

Create app.py

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