farida5gaber commited on
Commit
3794961
·
verified ·
1 Parent(s): 197ebbb

Update webapp.py

Browse files
Files changed (1) hide show
  1. webapp.py +22 -6
webapp.py CHANGED
@@ -10,10 +10,26 @@ MODEL_ID = "gemini-2.5-flash" # Replace with your desired model ID
10
 
11
  def google_search_query(question, use_web_search):
12
  try:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
13
  # Generate the AI response without web search initially
14
  response = client.models.generate_content(
15
  model=MODEL_ID,
16
- contents=question,
17
  )
18
  ai_response = response.text # AI response as plain text
19
 
@@ -22,7 +38,7 @@ def google_search_query(question, use_web_search):
22
  google_search_tool = Tool(google_search=GoogleSearch())
23
  response = client.models.generate_content(
24
  model=MODEL_ID,
25
- contents=question,
26
  config=GenerateContentConfig(tools=[google_search_tool]),
27
  )
28
  search_results = response.candidates[0].grounding_metadata.search_entry_point.rendered_content
@@ -34,12 +50,12 @@ def google_search_query(question, use_web_search):
34
  return f"Error: {str(e)}", ""
35
 
36
  # Gradio Interface using Chatbot and conditional web search
37
- with gr.Blocks(theme=gr.themes.Glass(secondary_hue = "violet")) as app:
38
- gr.Markdown("# Gemini 2.0 Google Search Custom UI")
39
  with gr.Row():
40
- chatbot = gr.Chatbot(label="Chatbot Responses")
41
  with gr.Row():
42
- question_input = gr.Textbox(lines=2, label="Ask a Question")
43
  web_search_checkbox = gr.Checkbox(label="Enhance with Web Search", value=False)
44
  with gr.Row():
45
  submit_button = gr.Button("Submit")
 
10
 
11
  def google_search_query(question, use_web_search):
12
  try:
13
+ perfume_prompt = f"""
14
+ You are an expert perfumer and fragrance production specialist.
15
+
16
+ Answer strictly in the context of:
17
+ - Perfumes and fine fragrances
18
+ - Perfume formulation and production processes
19
+ - Natural and synthetic fragrance ingredients
20
+ - Extraction techniques (steam distillation, solvent extraction, CO2 extraction, enfleurage)
21
+ - Blending, accords, top/middle/base notes
22
+ - Stability, safety, and IFRA compliance
23
+ - Industrial and artisanal perfume manufacturing
24
+
25
+ Question:
26
+ {question}
27
+ """
28
+
29
  # Generate the AI response without web search initially
30
  response = client.models.generate_content(
31
  model=MODEL_ID,
32
+ contents=perfume_prompt,
33
  )
34
  ai_response = response.text # AI response as plain text
35
 
 
38
  google_search_tool = Tool(google_search=GoogleSearch())
39
  response = client.models.generate_content(
40
  model=MODEL_ID,
41
+ contents=perfume_prompt,
42
  config=GenerateContentConfig(tools=[google_search_tool]),
43
  )
44
  search_results = response.candidates[0].grounding_metadata.search_entry_point.rendered_content
 
50
  return f"Error: {str(e)}", ""
51
 
52
  # Gradio Interface using Chatbot and conditional web search
53
+ with gr.Blocks(theme=gr.themes.Glass(secondary_hue="violet")) as app:
54
+ gr.Markdown("# Perfume Production Assistant (Gemini + Google Search)")
55
  with gr.Row():
56
+ chatbot = gr.Chatbot(label="Perfume Expert Responses")
57
  with gr.Row():
58
+ question_input = gr.Textbox(lines=2, label="Ask a Question about Perfumes")
59
  web_search_checkbox = gr.Checkbox(label="Enhance with Web Search", value=False)
60
  with gr.Row():
61
  submit_button = gr.Button("Submit")