Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -20,11 +20,11 @@ client = OpenAI(api_key=OPENAI_API_KEY)
|
|
20 |
fastapi_app = FastAPI()
|
21 |
|
22 |
@fastapi_app.get("/initial_prompt")
|
23 |
-
def get_initial_prompt():
|
24 |
return {"prompt": INITIAL_PROMPT}
|
25 |
|
26 |
@fastapi_app.get("/main_prompt")
|
27 |
-
def get_main_prompt():
|
28 |
return {"prompt": MAIN_PROMPT}
|
29 |
|
30 |
# ✅ Chatbot Function
|
@@ -66,37 +66,36 @@ def respond(user_message, history):
|
|
66 |
return "", history
|
67 |
|
68 |
# ✅ Gradio UI
|
69 |
-
|
70 |
-
gr.
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
threading.Thread(target=run_gradio).start()
|
100 |
-
|
101 |
if __name__ == "__main__":
|
|
|
102 |
uvicorn.run(fastapi_app, host="0.0.0.0", port=8000)
|
|
|
20 |
fastapi_app = FastAPI()
|
21 |
|
22 |
@fastapi_app.get("/initial_prompt")
|
23 |
+
async def get_initial_prompt():
|
24 |
return {"prompt": INITIAL_PROMPT}
|
25 |
|
26 |
@fastapi_app.get("/main_prompt")
|
27 |
+
async def get_main_prompt():
|
28 |
return {"prompt": MAIN_PROMPT}
|
29 |
|
30 |
# ✅ Chatbot Function
|
|
|
66 |
return "", history
|
67 |
|
68 |
# ✅ Gradio UI
|
69 |
+
def launch_gradio():
|
70 |
+
with gr.Blocks() as gradio_app:
|
71 |
+
gr.Markdown("## Simple Chat Interface")
|
72 |
+
|
73 |
+
chatbot = gr.Chatbot(
|
74 |
+
value=[{"role": "assistant", "content": INITIAL_PROMPT}],
|
75 |
+
height=500,
|
76 |
+
type="messages"
|
77 |
+
)
|
78 |
+
|
79 |
+
state_history = gr.State([("", INITIAL_PROMPT)])
|
80 |
+
|
81 |
+
user_input = gr.Textbox(
|
82 |
+
placeholder="Type your message here...",
|
83 |
+
label="Your Input"
|
84 |
+
)
|
85 |
+
|
86 |
+
user_input.submit(
|
87 |
+
respond,
|
88 |
+
inputs=[user_input, state_history],
|
89 |
+
outputs=[user_input, chatbot]
|
90 |
+
).then(
|
91 |
+
fn=lambda _, h: h,
|
92 |
+
inputs=[user_input, chatbot],
|
93 |
+
outputs=[state_history]
|
94 |
+
)
|
95 |
+
|
96 |
+
gradio_app.launch(server_name="0.0.0.0", server_port=7860, show_error=True, enable_queue=True)
|
97 |
+
|
98 |
+
# ✅ Run FastAPI and Gradio Separately
|
|
|
|
|
99 |
if __name__ == "__main__":
|
100 |
+
threading.Thread(target=launch_gradio, daemon=True).start()
|
101 |
uvicorn.run(fastapi_app, host="0.0.0.0", port=8000)
|