eudoxie commited on
Commit
8f2d18b
·
verified ·
1 Parent(s): 510b1d4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +40 -24
app.py CHANGED
@@ -47,29 +47,45 @@ rag_chain = (
47
  )
48
  import gradio as gr
49
 
50
- def rag_memory_stream(message, history):
51
- partial_text = ""
52
- for new_text in rag_chain.stream(message):
53
- partial_text += new_text
54
- yield partial_text
55
-
56
- greetingsmessage = """Hello! Welcome to MediGuide ChatBot. I'm here to provide you with quick and accurate information on medical drugs.
57
- Whether you need details on usage, side effects , etc feel free to ask. Let's enhance patient care together!"""
58
-
59
-
60
- title = "MediGuide ChatBot"
61
-
62
- demo = gr.Interface(
63
-
64
- title=title,
65
- fn=rag_memory_stream,
66
- inputs='text',
67
- outputs='text',
68
- allow_flagging="never",
69
- fill_height=True,
70
- theme=gr.themes.Soft(),
71
- )
72
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
73
 
74
- if __name__ == "__main__":
75
  demo.launch()
 
47
  )
48
  import gradio as gr
49
 
50
+ # Function to handle prompt and query the RAG chain
51
+ def handle_prompt(message, history):
52
+ try:
53
+ # Stream output
54
+ out=""
55
+ for chunk in rag_chain.stream(message):
56
+ out += chunk
57
+ yield out
58
+ except:
59
+ raise gr.Error("Requests rate limit exceeded")
60
+
61
+
62
+ if __name__=="__main__":
63
+
64
+ # Predefined messages and examples
65
+ description = "AI powered assistant which answers any question related to the [CAMELS simulations](https://www.camel-simulations.org/)."
66
+ greetingsmessage = "Hi, I'm the CAMELS DocBot, I'm here to assist you with any question related to the CAMELS simulations."
67
+ example_questions = [
68
+ "How can I read a halo file?",
69
+ "Which simulation suites are included in CAMELS?",
70
+ "Which are the largest volumes in CAMELS simulations?",
71
+ "Write a complete snippet of code getting the power spectrum of a simulation"
72
+ ]
73
+
74
+ # Define customized Gradio chatbot
75
+ chatbot = gr.Chatbot([{"role":"assistant", "content":greetingsmessage}],
76
+ type="messages",
77
+ avatar_images=["ims/userpic.png","ims/camelslogo.jpg"],
78
+ height="60vh")
79
+
80
+ # Define Gradio interface
81
+ demo = gr.ChatInterface(handle_prompt,
82
+ type="messages",
83
+ title="CAMELS DocBot",
84
+ fill_height=True,
85
+ examples=example_questions,
86
+ theme=gr.themes.Soft(),
87
+ description=description,
88
+ #cache_examples=False,
89
+ chatbot=chatbot)
90
 
 
91
  demo.launch()