Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -94,16 +94,17 @@ def generate_response(user_query, relevant_segment):
|
|
94 |
print(f"Error in generating response: {e}")
|
95 |
return f"Error in generating response: {e}"
|
96 |
|
97 |
-
def query_model(question):
|
98 |
"""
|
99 |
Process a question, find relevant information, and generate a response using inputted book title.
|
100 |
"""
|
101 |
if question == "":
|
102 |
return "Welcome to LitBot! Ask me anything about literature, book themes, and the historical context behind your book."
|
103 |
-
|
|
|
104 |
if not relevant_segment:
|
105 |
return "Could not find specific information. Please refine your question."
|
106 |
-
response = generate_response(
|
107 |
return response
|
108 |
|
109 |
# Define the welcome message and specific topics the chatbot can provide information about
|
@@ -149,15 +150,15 @@ with gr.Blocks(theme='JohnSmith9982/small_and_pretty') as demo:
|
|
149 |
gr.Markdown(topics)
|
150 |
with gr.Row():
|
151 |
with gr.Column():
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
question = gr.Textbox(label="Your question", placeholder="What do you want to ask about?")
|
157 |
gr.Markdown(space)
|
158 |
submit_button = gr.Button("Submit")
|
159 |
answer = gr.Textbox(label="LitBot Response", placeholder="LitBot will respond here...", interactive=False, lines=30)
|
160 |
-
submit_button.click(fn=query_model, inputs=question, outputs=answer)
|
161 |
|
162 |
|
163 |
# Launch the Gradio app to allow user interaction
|
|
|
94 |
print(f"Error in generating response: {e}")
|
95 |
return f"Error in generating response: {e}"
|
96 |
|
97 |
+
def query_model(question, book):
|
98 |
"""
|
99 |
Process a question, find relevant information, and generate a response using inputted book title.
|
100 |
"""
|
101 |
if question == "":
|
102 |
return "Welcome to LitBot! Ask me anything about literature, book themes, and the historical context behind your book."
|
103 |
+
full_query = f"{book}: {question}"
|
104 |
+
relevant_segment = find_relevant_segment(full_query, segments)
|
105 |
if not relevant_segment:
|
106 |
return "Could not find specific information. Please refine your question."
|
107 |
+
response = generate_response(full_query, relevant_segment)
|
108 |
return response
|
109 |
|
110 |
# Define the welcome message and specific topics the chatbot can provide information about
|
|
|
150 |
gr.Markdown(topics)
|
151 |
with gr.Row():
|
152 |
with gr.Column():
|
153 |
+
book = gr.Dropdown(
|
154 |
+
["The Great Gatsby", "The Crucible", "Fahrenheit 451", "Of Mice and Men", "To Kill a Mockingbird", "Romeo and Juliet", "The Catcher in the Rye", "Pride and Prejudice", "Lord of the Flies", "Hamlet"],
|
155 |
+
label = "Choose a book!",
|
156 |
+
interactive = True )
|
157 |
question = gr.Textbox(label="Your question", placeholder="What do you want to ask about?")
|
158 |
gr.Markdown(space)
|
159 |
submit_button = gr.Button("Submit")
|
160 |
answer = gr.Textbox(label="LitBot Response", placeholder="LitBot will respond here...", interactive=False, lines=30)
|
161 |
+
submit_button.click(fn=query_model, inputs=[question, book], outputs=answer)
|
162 |
|
163 |
|
164 |
# Launch the Gradio app to allow user interaction
|