Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -11,7 +11,7 @@ retrieval_model_name = 'output/sentence-transformer-finetuned/'
|
|
11 |
|
12 |
openai.api_key = os.environ["OPENAI_API_KEY"]
|
13 |
|
14 |
-
system_message = "You are an
|
15 |
# Initial system message to set the behavior of the assistant
|
16 |
messages = [{"role": "system", "content": system_message}]
|
17 |
|
@@ -73,9 +73,9 @@ def generate_response(user_query, relevant_segment):
|
|
73 |
messages.append({"role": "user", "content": user_message})
|
74 |
|
75 |
response = openai.ChatCompletion.create(
|
76 |
-
model="gpt-
|
77 |
messages=messages,
|
78 |
-
max_tokens=
|
79 |
temperature=0.2,
|
80 |
top_p=1,
|
81 |
frequency_penalty=0,
|
@@ -100,16 +100,20 @@ def query_model(question):
|
|
100 |
"""
|
101 |
if question == "":
|
102 |
return "Welcome to Starfinder! Ask me anything about outer space, stargazing, and upcoming astronomical events."
|
|
|
|
|
|
|
|
|
|
|
103 |
relevant_segment = find_relevant_segment(question, segments)
|
104 |
if not relevant_segment:
|
105 |
return "Could not find specific information. Please refine your question."
|
106 |
response = generate_response(question, relevant_segment)
|
107 |
-
return response
|
108 |
|
109 |
# Define the welcome message and specific topics the chatbot can provide information about
|
110 |
welcome_message = """
|
111 |
# ♟️ Welcome to Starfinder!
|
112 |
-
|
113 |
## Your AI-driven assistant for all astronomy-related queries. Created by Aarna, Aditi, and Anastasia of the 2024 Kode With Klossy SF Camp.
|
114 |
"""
|
115 |
|
@@ -122,21 +126,9 @@ topics = """
|
|
122 |
- Celestial events
|
123 |
- Astronomy tips
|
124 |
"""
|
125 |
-
|
126 |
-
background_fill_primary='#FFD700', # Light yellow background
|
127 |
-
background_fill_primary_dark='#FFD700', # Darker yellow background
|
128 |
-
background_fill_secondary='#3E92CC', # Light blue background
|
129 |
-
background_fill_secondary_dark='#2A628F', # Darker blue background
|
130 |
-
border_color_accent='#16324F', # Accent border color (dark blue)
|
131 |
-
border_color_accent_dark='#16324F', # Dark accent border color (dark blue)
|
132 |
-
border_color_accent_subdued='#18435A', # Subdued accent border color (slightly lighter blue)
|
133 |
-
border_color_primary='#2A628F', # Primary border color (medium blue)
|
134 |
-
block_border_color='#2A628F', # Block border color (medium blue)
|
135 |
-
button_primary_background_fill='#2A628F', # Primary button background color (medium blue)
|
136 |
-
button_primary_background_fill_dark='#2A628F' # Dark primary button background color (medium blue)
|
137 |
-
)
|
138 |
# Setup the Gradio Blocks interface with custom layout components
|
139 |
-
with gr.Blocks(theme=
|
140 |
gr.Markdown(welcome_message) # Display the formatted welcome message
|
141 |
with gr.Row():
|
142 |
with gr.Column():
|
@@ -145,9 +137,12 @@ with gr.Blocks(theme=STARS) as demo:
|
|
145 |
with gr.Column():
|
146 |
question = gr.Textbox(label="Your question", placeholder="What do you want to ask about?")
|
147 |
answer = gr.Textbox(label="StarFinder Response", placeholder="StarFinder will respond here...", interactive=False, lines=10)
|
|
|
148 |
submit_button = gr.Button("Submit")
|
149 |
-
submit_button.click(fn=query_model, inputs=question, outputs=answer)
|
150 |
|
151 |
|
152 |
# Launch the Gradio app to allow user interaction
|
153 |
demo.launch(share=True)
|
|
|
|
|
|
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."
|
15 |
# Initial system message to set the behavior of the assistant
|
16 |
messages = [{"role": "system", "content": system_message}]
|
17 |
|
|
|
73 |
messages.append({"role": "user", "content": user_message})
|
74 |
|
75 |
response = openai.ChatCompletion.create(
|
76 |
+
model="gpt-3.5-turbo",
|
77 |
messages=messages,
|
78 |
+
max_tokens=150,
|
79 |
temperature=0.2,
|
80 |
top_p=1,
|
81 |
frequency_penalty=0,
|
|
|
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 |
|
114 |
# Define the welcome message and specific topics the chatbot can provide information about
|
115 |
welcome_message = """
|
116 |
# ♟️ Welcome to Starfinder!
|
|
|
117 |
## Your AI-driven assistant for all astronomy-related queries. Created by Aarna, Aditi, and Anastasia of the 2024 Kode With Klossy SF Camp.
|
118 |
"""
|
119 |
|
|
|
126 |
- Celestial events
|
127 |
- Astronomy tips
|
128 |
"""
|
129 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
130 |
# Setup the Gradio Blocks interface with custom layout components
|
131 |
+
with gr.Blocks(theme='JohnSmith9982/small_and_pretty') as demo:
|
132 |
gr.Markdown(welcome_message) # Display the formatted welcome message
|
133 |
with gr.Row():
|
134 |
with gr.Column():
|
|
|
137 |
with gr.Column():
|
138 |
question = gr.Textbox(label="Your question", placeholder="What do you want to ask about?")
|
139 |
answer = gr.Textbox(label="StarFinder Response", placeholder="StarFinder will respond here...", interactive=False, lines=10)
|
140 |
+
image_output = gr.Image(label="Image Output") # Add an Image component
|
141 |
submit_button = gr.Button("Submit")
|
142 |
+
submit_button.click(fn=query_model, inputs=question, outputs=[answer, image_output]) # Update outputs to include the image component
|
143 |
|
144 |
|
145 |
# Launch the Gradio app to allow user interaction
|
146 |
demo.launch(share=True)
|
147 |
+
|
148 |
+
|