Aarnaburji commited on
Commit
e8f37b2
·
verified ·
1 Parent(s): de99f55

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -7
app.py CHANGED
@@ -9,6 +9,11 @@ os.environ["TOKENIZERS_PARALLELISM"] = "false"
9
  filename = "output_topic_details.txt" # Path to the file storing chess-specific details
10
  retrieval_model_name = 'output/sentence-transformer-finetuned/'
11
 
 
 
 
 
 
12
  openai.api_key = os.environ["OPENAI_API_KEY"]
13
 
14
  system_message = "You are an astronomy chatbot named Starfinder specialized in providing information on stargazing, astronomical events, and outer space."
@@ -99,15 +104,18 @@ def query_model(question):
99
  Process a question, find relevant information, and generate a response.
100
  """
101
  if question == "":
102
- return "Welcome to Starfinder! Ask me anything about outer space, stargazing, and upcoming astronomical events."
103
 
104
  if "san francisco" in question.lower():
105
- # Return the image path and a message
106
- return "Here is a picture of San Francisco!", "/path/to/your/san-francisco.jpg"
 
 
 
107
 
108
  relevant_segment = find_relevant_segment(question, segments)
109
  if not relevant_segment:
110
- return "Could not find specific information. Please refine your question."
111
  response = generate_response(question, relevant_segment)
112
  return response, None
113
 
@@ -126,7 +134,6 @@ topics = """
126
  - Celestial events
127
  - Astronomy tips
128
  """
129
- import gradio as gr
130
 
131
  STARS = gr.themes.Base().set(
132
  background_fill_primary='#2A628F', # Light yellow background
@@ -139,7 +146,6 @@ STARS = gr.themes.Base().set(
139
  border_color_primary='#2A628F', # Primary border color (medium blue)
140
  block_border_color='#2A628F', # Block border color (medium blue)
141
  button_primary_background_fill='#2A628F', # Primary button background color (medium blue)
142
-
143
  )
144
 
145
  # Setup the Gradio Blocks interface with custom layout components
@@ -155,9 +161,10 @@ with gr.Blocks(theme=STARS) as demo:
155
  image_output = gr.Image(label="Image Output") # Add an Image component
156
  submit_button = gr.Button("Submit")
157
  submit_button.click(fn=query_model, inputs=question, outputs=[answer, image_output]) # Update outputs to include the image component
158
-
159
 
160
  # Launch the Gradio app to allow user interaction
161
  demo.launch(share=True)
162
 
163
 
 
 
 
9
  filename = "output_topic_details.txt" # Path to the file storing chess-specific details
10
  retrieval_model_name = 'output/sentence-transformer-finetuned/'
11
 
12
+ # Define paths to images
13
+ path_to_sf_image = "output/sf.png"
14
+ path_to_sacramento_image = "output/sacramento.png"
15
+ path_to_la_image = "output/la.png"
16
+
17
  openai.api_key = os.environ["OPENAI_API_KEY"]
18
 
19
  system_message = "You are an astronomy chatbot named Starfinder specialized in providing information on stargazing, astronomical events, and outer space."
 
104
  Process a question, find relevant information, and generate a response.
105
  """
106
  if question == "":
107
+ return "Welcome to Starfinder! Ask me anything about outer space, stargazing, and upcoming astronomical events.", None
108
 
109
  if "san francisco" in question.lower():
110
+ return "Here is a picture of San Francisco!", path_to_sf_image
111
+ if "sacramento" in question.lower():
112
+ return "Here is a picture of Sacramento!", path_to_sacramento_image
113
+ if "los angeles" in question.lower() or "la" in question.lower():
114
+ return "Here is a picture of Los Angeles!", path_to_la_image
115
 
116
  relevant_segment = find_relevant_segment(question, segments)
117
  if not relevant_segment:
118
+ return "Could not find specific information. Please refine your question.", None
119
  response = generate_response(question, relevant_segment)
120
  return response, None
121
 
 
134
  - Celestial events
135
  - Astronomy tips
136
  """
 
137
 
138
  STARS = gr.themes.Base().set(
139
  background_fill_primary='#2A628F', # Light yellow background
 
146
  border_color_primary='#2A628F', # Primary border color (medium blue)
147
  block_border_color='#2A628F', # Block border color (medium blue)
148
  button_primary_background_fill='#2A628F', # Primary button background color (medium blue)
 
149
  )
150
 
151
  # Setup the Gradio Blocks interface with custom layout components
 
161
  image_output = gr.Image(label="Image Output") # Add an Image component
162
  submit_button = gr.Button("Submit")
163
  submit_button.click(fn=query_model, inputs=question, outputs=[answer, image_output]) # Update outputs to include the image component
 
164
 
165
  # Launch the Gradio app to allow user interaction
166
  demo.launch(share=True)
167
 
168
 
169
+
170
+