Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -63,6 +63,7 @@ def find_relevant_segment(user_query, segments):
|
|
63 |
def generate_response(user_query, relevant_segment):
|
64 |
"""
|
65 |
Generate a response emphasizing the bot's capability to provide information related to composting food.
|
|
|
66 |
try:
|
67 |
system_message = "You are a chatbot specialized in providing information about food composting tips, tricks, and basics."
|
68 |
user_message = f"Here's the information on composting: {relevant_segment}"
|
@@ -83,17 +84,6 @@ def generate_response(user_query, relevant_segment):
|
|
83 |
except Exception as e:
|
84 |
print(f"Error in generating response: {e}")
|
85 |
return f"Error in generating response: {e}"
|
86 |
-
"""
|
87 |
-
# Create pipeline for text generation with confidence scores
|
88 |
-
generator = pipeline("text-davinci-003", device=0) # Adjust device if needed
|
89 |
-
|
90 |
-
# Generate response and get confidence score
|
91 |
-
response = generator(query=f"Here's the information on chess: {relevant_segment} {user_query}", max_length=150, temperature=0.2, top_p=1)
|
92 |
-
generated_text = response[0]['generated_text'].strip()
|
93 |
-
confidence_score = response[0]['score']
|
94 |
-
|
95 |
-
return generated_text, confidence_score
|
96 |
-
|
97 |
|
98 |
def query_model(question):
|
99 |
"""
|
@@ -140,15 +130,6 @@ with gr.Blocks(theme='gradio/seafoam') as demo:
|
|
140 |
submit_button = gr.Button("Submit")
|
141 |
submit_button.click(fn=query_model, inputs=question, outputs=answer)
|
142 |
|
143 |
-
answer = gr.Textbox(label="CompBot Response", placeholder="CompBot's response is...", interactive=False, lines=5)
|
144 |
-
submit_button = gr.Button("Submit")
|
145 |
-
|
146 |
-
def display_response(question):
|
147 |
-
response, confidence_score = query_model(question)
|
148 |
-
answer.value = f"Response: {response}\nConfidence Score: {confidence_score:.2f}"
|
149 |
-
|
150 |
-
submit_button.click(fn=display_response, inputs=question, outputs=None)
|
151 |
-
|
152 |
|
153 |
# Launch the Gradio app to allow user interaction
|
154 |
demo.launch(share=True)
|
|
|
63 |
def generate_response(user_query, relevant_segment):
|
64 |
"""
|
65 |
Generate a response emphasizing the bot's capability to provide information related to composting food.
|
66 |
+
"""
|
67 |
try:
|
68 |
system_message = "You are a chatbot specialized in providing information about food composting tips, tricks, and basics."
|
69 |
user_message = f"Here's the information on composting: {relevant_segment}"
|
|
|
84 |
except Exception as e:
|
85 |
print(f"Error in generating response: {e}")
|
86 |
return f"Error in generating response: {e}"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
87 |
|
88 |
def query_model(question):
|
89 |
"""
|
|
|
130 |
submit_button = gr.Button("Submit")
|
131 |
submit_button.click(fn=query_model, inputs=question, outputs=answer)
|
132 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
133 |
|
134 |
# Launch the Gradio app to allow user interaction
|
135 |
demo.launch(share=True)
|