Shanulhaq commited on
Commit
bf970e6
1 Parent(s): 045f8ed

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +47 -0
app.py ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import google.generativeai as genai
3
+
4
+ # Configure API Key
5
+ GOOGLE_API_KEY = "675826031094"
6
+ genai.configure(api_key=GOOGLE_API_KEY)
7
+
8
+ # Initialize the Generative Model
9
+ model = genai.GenerativeModel(
10
+ 'gemini-1.5-flash',
11
+ system_instruction=(
12
+ "Persona: You are a heart specialist with the name of Dr. Assad Siddiqui. Only provide information related to heart health, symptoms, and advice."
13
+ "Ask users about their heart-related symptoms and provide consultation and guidance based on their input."
14
+ "Always provide brief answers. Additionally, if the inquiry is not related to heart health, politely say that you can only provide heart-related information."
15
+ "Responses should be in Urdu (written in Roman English) and English."
16
+ )
17
+ )
18
+
19
+ # Function to get response from the chatbot
20
+ def get_chatbot_response(user_input, chat_history):
21
+ response = model.generate_content(user_input)
22
+ bot_response = response.text.strip()
23
+
24
+ chat_history.append((user_input, bot_response))
25
+ return chat_history, chat_history
26
+
27
+ # Gradio Interface
28
+ def chat(user_input, history):
29
+ return get_chatbot_response(user_input, history)
30
+
31
+ with gr.Blocks() as demo:
32
+ gr.Markdown("<h1 style='text-align:center;'>Heart Health Chatbot 🫀</h1>")
33
+ gr.Markdown("<p style='text-align:center;'>Ask Dr. Assad Siddiqui about heart health in both Urdu and English!</p>")
34
+
35
+ chat_history = gr.State([])
36
+
37
+ chatbot = gr.Chatbot(label="Heart Health Chatbot").style(height=500)
38
+ user_input = gr.Textbox(placeholder="Type your message here...")
39
+
40
+ user_input.submit(chat, [user_input, chat_history], [chatbot, chat_history])
41
+ gr.Examples(examples=["What are common heart disease symptoms?", "Mujhe dil ki takleef hai. Kya karoon?"],
42
+ inputs=user_input)
43
+
44
+ gr.Markdown("<p style='text-align:center;'>Made with ❤️ by Assad Siddiqui</p>")
45
+
46
+ # Launch the Gradio interface
47
+ demo.launch()