Manar11 commited on
Commit
e473a8b
·
verified ·
1 Parent(s): c75ac87

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -12
app.py CHANGED
@@ -14,7 +14,7 @@ IMAGE_WIDTH = 512
14
 
15
  system_instruction_analysis = "You are an expert of the given topic. Analyze the provided text with a focus on the topic, identifying recent issues, recent insights, or improvements relevant to academic standards and effectiveness. Offer actionable advice for enhancing knowledge and suggest real-life examples."
16
  model_name = "gemini-2.0-flash-exp"
17
- model = genai.GenerativeModel(model_name, system_instruction=system_instruction_analysis)
18
  #genai.configure(api_key=google_key)
19
 
20
  # Helper Functions
@@ -38,9 +38,12 @@ def bot(
38
  top_p: float,
39
  chatbot: List[Tuple[str, str]]
40
  ):
41
- google_key = google_key or GOOGLE_API_KEY
42
- if not google_key:
43
- raise ValueError("GOOGLE_API_KEY is not set. Please set it up.")
 
 
 
44
 
45
  text_prompt = chatbot[-1][0].strip() if chatbot[-1][0] else None
46
 
@@ -57,14 +60,15 @@ def bot(
57
  text_prompt = f"{text_prompt}. Also, analyze the provided image."
58
 
59
  # Configure the model
60
- genai.configure(api_key=google_key)
61
- generation_config = genai.types.GenerationConfig(
62
- temperature=temperature,
63
- max_output_tokens=max_output_tokens,
64
- stop_sequences=preprocess_stop_sequences(stop_sequences),
65
- top_k=top_k,
66
- top_p=top_p,
67
- )
 
68
 
69
  # Prepare inputs
70
  inputs = [text_prompt] if image_prompt is None else [text_prompt, preprocess_image(image_prompt)]
 
14
 
15
  system_instruction_analysis = "You are an expert of the given topic. Analyze the provided text with a focus on the topic, identifying recent issues, recent insights, or improvements relevant to academic standards and effectiveness. Offer actionable advice for enhancing knowledge and suggest real-life examples."
16
  model_name = "gemini-2.0-flash-exp"
17
+ #model = genai.GenerativeModel(model_name, system_instruction=system_instruction_analysis)
18
  #genai.configure(api_key=google_key)
19
 
20
  # Helper Functions
 
38
  top_p: float,
39
  chatbot: List[Tuple[str, str]]
40
  ):
41
+ #google_key = google_key or GOOGLE_API_KEY
42
+ used_api_key = google_key if google_key else GOOGLE_API_KEY
43
+ if not used_api_key:
44
+ chatbot[-1][1] = "❌ No API Key found! Please provide it."
45
+ yield chatbot
46
+ return
47
 
48
  text_prompt = chatbot[-1][0].strip() if chatbot[-1][0] else None
49
 
 
60
  text_prompt = f"{text_prompt}. Also, analyze the provided image."
61
 
62
  # Configure the model
63
+ genai.configure(api_key=used_api_key)
64
+ #generation_config = genai.types.GenerationConfig(
65
+ # temperature=temperature,
66
+ # max_output_tokens=max_output_tokens,
67
+ # stop_sequences=preprocess_stop_sequences(stop_sequences),
68
+ # top_k=top_k,
69
+ # top_p=top_p,
70
+ #)
71
+ model = genai.GenerativeModel(model_name, system_instruction=system_instruction_analysis)
72
 
73
  # Prepare inputs
74
  inputs = [text_prompt] if image_prompt is None else [text_prompt, preprocess_image(image_prompt)]