Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from openai import OpenAI
|
3 |
+
|
4 |
+
def generate_response(user_input):
|
5 |
+
client = OpenAI()
|
6 |
+
response = client.responses.create(
|
7 |
+
model="gpt-4o",
|
8 |
+
input=[
|
9 |
+
{
|
10 |
+
"role": "system",
|
11 |
+
"content": [
|
12 |
+
{
|
13 |
+
"type": "input_text",
|
14 |
+
"text": user_input
|
15 |
+
}
|
16 |
+
]
|
17 |
+
}
|
18 |
+
],
|
19 |
+
text={
|
20 |
+
"format": {
|
21 |
+
"type": "text"
|
22 |
+
}
|
23 |
+
},
|
24 |
+
reasoning={},
|
25 |
+
tools=[],
|
26 |
+
temperature=1,
|
27 |
+
max_output_tokens=2048,
|
28 |
+
top_p=1,
|
29 |
+
store=True
|
30 |
+
)
|
31 |
+
|
32 |
+
return response.text # Adjust based on OpenAI response format
|
33 |
+
|
34 |
+
# Gradio UI
|
35 |
+
demo = gr.Interface(
|
36 |
+
fn=generate_response,
|
37 |
+
inputs=gr.Textbox(label="Enter your prompt"),
|
38 |
+
outputs=gr.Textbox(label="Generated Response"),
|
39 |
+
title="OpenAI GPT-4o Bot Guide Generator",
|
40 |
+
description="Enter a request, and the bot will generate a response using OpenAI's API."
|
41 |
+
)
|
42 |
+
|
43 |
+
demo.launch()
|