Spaces:
Build error

Flow_GPT / app.py
richterts's picture
Update app.py
de91866
Raw History Blame Contribute Delete
2.51 kB
import gradio as gr
import openai
import os
import langchain
from langchain.chat_models import ChatOpenAI
from langchain.schema import AIMessage, HumanMessage
#import config
#openai.api_key = config.OPENAI_API_KEY
#openai.api_key = OPENAI_API_KEY
openai.api_key = os.environ["OPENAI_API_KEY"]
#news_api_key = os.environ["NEWS_API_KEY"]
#message_history = [{"role": "user", "content": f"You are Genius doctor, who is trying to determine and provide accurate diagnosis, ask questions to identify symptoms, clinic history, life style, psychosocial factors, allergies, or any recent events that could have negative impact or that could be the root cause of illness. Ask any other questions that you consider you need to know in order to came up with an accurate diagnosis and guide the patient for the next steps in terms of best physician or specialist that he/she should visit. At the end emphazise that you need to contact your personal doctor"},
# {"role": "assistant", "content": f"OK"}]
#message_history = [{"role": "user", "content": f"You are Genius materiality specialist, give suggestions and current trends with examples and ask any other questions that you consider you need to know in order to came up with an suggestion in terms of product lifecycle analysis"},
# {"role": "assistant", "content": f"OK"}]
message = [{"role": "user", "content": f"Act as a Genius doctor, at first introduce yourself as an AI Doctor and proceed to collect basic information to create patient profile,ask any set of questions that you consider you need to know in order to came up with an accurate diagnosis, once you have the diagnosis share information and provide the Spanish triage system (SET) category based on the diagnosis and guide the patient for the next steps in terms of best physician or specialist that he/she should visit. At the end emphazise that you need to contact your personal doctor"},
{"role": "assistant", "content": f"OK"}]
llm = ChatOpenAI(temperature=1.0, model='gpt-3.5-turbo-0613', openai_api_key=openai.api_key)
def predict(message, history):
history_langchain_format = []
for human, ai in history:
history_langchain_format.append(HumanMessage(content=human))
history_langchain_format.append(AIMessage(content=ai))
history_langchain_format.append(HumanMessage(content=message))
gpt_response = llm(history_langchain_format)
return gpt_response.content
gr.ChatInterface(predict).launch()