vinayakarsh commited on
Commit
3059833
·
verified ·
1 Parent(s): 74e7639

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -17
app.py CHANGED
@@ -3,20 +3,24 @@ import google.generativeai as genai
3
  import gradio as gr
4
  import time
5
 
6
- GOOGLE_API_KEY = os.getenv('GOOGLE_API_KEY')
7
- genai.configure(api_key=GOOGLE_API_KEY)
 
8
 
9
- system_instruction = "You are an expert in medical report analysis and a medical professional. Analyze the given medical report and generate a summarized report of the same."\
10
- "All the medical tests in the given medical report must be specified in the summarized report. The response generated should be well-structured with health tips based on the report."
11
 
12
- generation_config = genai.GenerationConfig(temperature=0)
13
- model = genai.GenerativeModel('gemini-2.0-flash-exp',
14
- system_instruction=system_instruction,
15
- generation_config=generation_config)
16
 
17
- chat = model.start_chat()
18
- stop_generation = None
19
- prompt = input_file = None
 
 
 
20
 
21
  def stop():
22
  global stop_generation
@@ -26,6 +30,7 @@ def clear():
26
  for file in genai.list_files():
27
  file.delete()
28
 
 
29
  def add_message(history, message):
30
  global prompt,input_file,stop_generation
31
  stop_generation = 0
@@ -62,16 +67,16 @@ def bot(history):
62
  time.sleep(0.01)
63
  yield history
64
 
65
- with gr.Blocks() as demo:
66
-
67
- chatbot = gr.Chatbot(bubble_full_width=False, type="messages",height=550)
68
- chat_input = gr.MultimodalTextbox(interactive=True, placeholder="Enter message or upload file...", show_label=False, file_count="single")
69
 
70
  chat_msg = chat_input.submit(add_message, [chatbot, chat_input], [chatbot, chat_input])
71
  bot_msg = chat_msg.then(bot, chatbot, chatbot)
72
  bot_msg.then(lambda: gr.MultimodalTextbox(interactive=True, submit_btn=True, stop_btn=False, value=None), None, chat_input)
73
 
74
  chat_input.stop(stop)
75
- chatbot.clear(clear)
 
 
76
 
77
- demo.launch()
 
3
  import gradio as gr
4
  import time
5
 
6
+ if gr.NO_RELOAD:
7
+ GOOGLE_API_KEY = os.getenv('GOOGLE_API_KEY')
8
+ genai.configure(api_key=GOOGLE_API_KEY)
9
 
10
+ system_instruction = "You are an expert in medical report analysis and a medical professional. Analyze the given medical report and generate a summarized report of the same."\
11
+ "All the medical tests in the given medical report must be specified in the summarized report. The response generated should be well-structured with health tips based on the report."
12
 
13
+ generation_config = genai.GenerationConfig(temperature=0)
14
+ model = genai.GenerativeModel('gemini-2.0-flash-exp',
15
+ system_instruction=system_instruction,
16
+ generation_config=generation_config)
17
 
18
+ chat = model.start_chat()
19
+
20
+ stop_generation = None
21
+ prompt = input_file = None
22
+
23
+ theme = gr.themes.Default(text_size=gr.themes.sizes.text_sm,font=[gr.themes.GoogleFont("Inconsolata"), "Arial", "sans-serif"])
24
 
25
  def stop():
26
  global stop_generation
 
30
  for file in genai.list_files():
31
  file.delete()
32
 
33
+
34
  def add_message(history, message):
35
  global prompt,input_file,stop_generation
36
  stop_generation = 0
 
67
  time.sleep(0.01)
68
  yield history
69
 
70
+ with gr.Blocks(theme=theme) as demo:
71
+ chatbot = gr.Chatbot(bubble_full_width=False, type="messages",height=550,container=False)
72
+ chat_input = gr.MultimodalTextbox(interactive=True, placeholder="Enter message or upload file...", show_label=False, file_count="single",container=False)
 
73
 
74
  chat_msg = chat_input.submit(add_message, [chatbot, chat_input], [chatbot, chat_input])
75
  bot_msg = chat_msg.then(bot, chatbot, chatbot)
76
  bot_msg.then(lambda: gr.MultimodalTextbox(interactive=True, submit_btn=True, stop_btn=False, value=None), None, chat_input)
77
 
78
  chat_input.stop(stop)
79
+ chatbot.clear(clear)
80
+
81
+ demo.launch()
82