utkuarslan5's picture
Update app.py
301b9eb
import gradio as gr
import requests
import json
from typing import List
def predict(message: str, history: List[List[str]], about_me: str) -> str:
"""
Predicts a response to a given message using the financial_bot Gradio UI.
Args:
message (str): The message to generate a response for.
history (List[List[str]]): A list of previous conversations.
about_me (str): A string describing the user.
Returns:
str: The generated response.
"""
payload = {
"about_me": about_me,
"question": message,
"to_load_history": history,
}
url = "https://idzhj.apps.beam.cloud"
headers = {
"Accept": "*/*",
"Accept-Encoding": "gzip, deflate",
"Authorization": "Basic YTZkOWY4NDVkODEyN2ZjY2NmMjcwNGFiMmRlNTY0YWE6NzQxMGMxMGIzYzA1OTc0YjIxZjU1NDQ5MDIzM2ZhNzY=",
"Connection": "keep-alive",
"Content-Type": "application/json"
}
response = requests.request("POST", url,
headers=headers,
data=json.dumps(payload)
)
return response
demo = gr.ChatInterface(
predict,
textbox=gr.Textbox(
placeholder="Ask me a financial question",
label="Financial question",
container=False,
scale=7,
),
additional_inputs=[
gr.Textbox(
"I am a student and I have some money that I want to invest.",
label="About me",
)
],
title="Your Personal Financial Assistant",
description="Ask me any financial or crypto market questions, and I will do my best to answer them.",
theme="soft",
examples=[
[
"What's your opinion on investing in startup companies?",
"I am a 30 year old graphic designer. I want to invest in something with potential for high returns.",
],
[
"What's your opinion on investing in AI-related companies?",
"I'm a 25 year old entrepreneur interested in emerging technologies. \
I'm willing to take calculated risks for potential high returns.",
],
[
"Do you think advancements in gene therapy are impacting biotech company valuations?",
"I'm a 31 year old scientist. I'm curious about the potential of biotech investments.",
],
],
cache_examples=False,
retry_btn=None,
undo_btn=None,
clear_btn="Clear",
)
demo.queue().launch(server_name="0.0.0.0", server_port=7860, share=True)