AliZain1 commited on
Commit
44f4f2e
·
verified ·
1 Parent(s): 6307f4c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -6
app.py CHANGED
@@ -9,17 +9,26 @@ import google.generativeai as genai
9
  GOOGLE_API_KEY = "AIzaSyB6WzzQDu0TOPieyAm6nygPAfa6LBudqNo"
10
  genai.configure(api_key=GOOGLE_API_KEY)
11
 
 
 
 
 
 
12
 
13
  def get_gemini_response(input_text, image_text=""):
14
  model = genai.GenerativeModel('gemini-1.5-flash')
 
 
15
  if input_text and image_text:
16
- response = model.generate_content([input_text, image_text])
17
  elif input_text:
18
- response = model.generate_content(input_text)
19
  elif image_text:
20
- response = model.generate_content(image_text)
21
  else:
22
- response = None
 
 
23
  return response.text if response else "No valid input provided."
24
 
25
 
@@ -31,10 +40,10 @@ def extract_text_from_pdf(pdf_file):
31
  return text
32
 
33
 
34
- # Initialize our Streamlit app
35
  st.set_page_config(page_title="Gemini Image and PDF Demo")
36
 
37
- st.header("Gemini Application")
38
 
39
  input_text = st.text_input("Input Prompt: ", key="input")
40
  uploaded_file = st.file_uploader("Choose an image or PDF...", type=["jpg", "jpeg", "png", "pdf"])
 
9
  GOOGLE_API_KEY = "AIzaSyB6WzzQDu0TOPieyAm6nygPAfa6LBudqNo"
10
  genai.configure(api_key=GOOGLE_API_KEY)
11
 
12
+ # Default prompt to ensure concise responses
13
+ DEFAULT_PROMPT = (
14
+ "You are an AI assistant. Provide all responses in concise, easy-to-read points, "
15
+ "limiting the entire response to 5 lines."
16
+ )
17
 
18
  def get_gemini_response(input_text, image_text=""):
19
  model = genai.GenerativeModel('gemini-1.5-flash')
20
+ combined_prompt = f"{DEFAULT_PROMPT}\n\n"
21
+
22
  if input_text and image_text:
23
+ combined_prompt += f"Prompt: {input_text}\nContent from PDF/Image: {image_text}"
24
  elif input_text:
25
+ combined_prompt += f"Prompt: {input_text}"
26
  elif image_text:
27
+ combined_prompt += f"Content from PDF/Image: {image_text}"
28
  else:
29
+ return "No valid input provided."
30
+
31
+ response = model.generate_content(combined_prompt)
32
  return response.text if response else "No valid input provided."
33
 
34
 
 
40
  return text
41
 
42
 
43
+ # Initialize Streamlit app
44
  st.set_page_config(page_title="Gemini Image and PDF Demo")
45
 
46
+ st.header("Chatbot Developed by Innoscope.ai")
47
 
48
  input_text = st.text_input("Input Prompt: ", key="input")
49
  uploaded_file = st.file_uploader("Choose an image or PDF...", type=["jpg", "jpeg", "png", "pdf"])