Southampton-GPT / app.py
Slycat's picture
Update app.py
d3a0f2d
raw
history blame
No virus
2.2 kB
from gradio_client import Client
from hugchat import hugchat
from hugchat.login import Login
import json
import gradio as gr
chat_client = Client("https://huggingfaceh4-falcon-chat.hf.space/")
retrieval = Client("https://slycat-southampton-similarity.hf.space/")
n_conv = 0
## Instruction: You are an AI language model and must return truthful responses as per the information below\n ##Input: Information: Your name is IITIGPT. You are a helpful and truthful chatbot. You can help answer any questions about the IIT Indore campus."
init_prompt =""
info="Information: \n"
q_prompt="\n ##Instruction: Please provide an appropriate response to the following: \n"
def change_conv():
# Create a new conversation
id = chatbot.new_conversation()
chatbot.change_conversation(id)
chatbot.chat(init_prompt)
chatbot.cookies = {}
def main(question):
global n_conv
# if(n_conv > 3):
# n_conv = 0
# change_conv(chatbot)
information = retrieval.predict(question, api_name = "/predict")
answer=chat_client.predict(
"Howdy!",
"new.json",
"You are an AI language model and must return truthful responses as per the information below\n ##Input: Information: Your name is Southampton GPT. You are a helpful and truthful chatbot. You can help answer any questions about the Southampton University." +information+question, # str in 'Type an input and press Enter' Textbox component
0.8,
0.9,
fn_index=4
)
try:
answer = chat_client.predict(
"Howdy!",
"new.json",
"You are an AI language model and must return truthful responses as per the information below\n ##Input: Information: Your name is IITIGPT. You are a helpful and truthful chatbot. You can help answer any questions about the IIT Indore campus." + information + question,
0.8,
0.9,
fn_index=4
)
if answer is None:
print("Chat client returned None.")
else:
print(answer)
n_conv+=1
except Exception as e:
print("Error:", str(e))
return answer
demo = gr.Interface(main,"text","text")
if __name__ == "__main__":
demo.launch()