Spaces:
Sleeping
Sleeping
akhilhsingh
commited on
Commit
•
c918151
1
Parent(s):
48e4139
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import requests
|
3 |
+
|
4 |
+
history = [] # Initialize an empty list to store conversation history
|
5 |
+
|
6 |
+
def chat_with_model(prompt,context):
|
7 |
+
# Ensure this URL matches your FastAPI configuration
|
8 |
+
global history
|
9 |
+
url = "http://43.205.120.87/chat"
|
10 |
+
# print(history)
|
11 |
+
response = requests.get(url, json={"prompt": prompt, "history": history})
|
12 |
+
|
13 |
+
if response.status_code == 200:
|
14 |
+
data = response.json()
|
15 |
+
history.append({"role": "user", "content": prompt}) # Add user's prompt to history
|
16 |
+
history.append({"role": "assistant", "content": data["response"]}) # Add bot's response to history
|
17 |
+
return data["response"]
|
18 |
+
else:
|
19 |
+
return "Error communicating with the backend."
|
20 |
+
|
21 |
+
# Defining the Gradio interface
|
22 |
+
iface = gr.ChatInterface(fn=chat_with_model,
|
23 |
+
textbox=gr.Textbox(placeholder="Type your message here..."),
|
24 |
+
#outputs=gr.Textbox(label="Chatbot's response"),
|
25 |
+
title="Akhil's Chatbot (powered by GPT-3.5 Turbo)",
|
26 |
+
theme='HaleyCH/HaleyCH_Theme',
|
27 |
+
# allow_flagging="never",
|
28 |
+
# css=custom_css,
|
29 |
+
description="Type your prompt and get a response from GPT-3.5 Turbo!")
|
30 |
+
iface.launch(share=True)
|