Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -65,6 +65,36 @@ def generate_response(user_query, relevant_segment):
|
|
65 |
"""
|
66 |
Generate a response emphasizing the bot's capability to provide information related to composting food.
|
67 |
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
68 |
try:
|
69 |
system_message = "You are a chatbot specialized in providing information about food composting tips, tricks, and basics."
|
70 |
user_message = f"Here's the information on composting: {relevant_segment}"
|
@@ -85,6 +115,7 @@ def generate_response(user_query, relevant_segment):
|
|
85 |
except Exception as e:
|
86 |
print(f"Error in generating response: {e}")
|
87 |
return f"Error in generating response: {e}"
|
|
|
88 |
|
89 |
|
90 |
def query_model(question):
|
@@ -119,7 +150,7 @@ topics = """
|
|
119 |
|
120 |
# Define the HTML iframe content
|
121 |
iframe = '''
|
122 |
-
<div style="height:
|
123 |
<iframe style="border-radius:12px"
|
124 |
src="https://open.spotify.com/embed/episode/1Emjgqf8PfwD42kvyKvtfW?utm_source=generator&theme=0"
|
125 |
width="100%" height="152" frameBorder="0"
|
|
|
65 |
"""
|
66 |
Generate a response emphasizing the bot's capability to provide information related to composting food.
|
67 |
"""
|
68 |
+
try:
|
69 |
+
# Define the messages
|
70 |
+
system_message = "You are a chatbot specialized in providing information about food composting tips, tricks, and basics."
|
71 |
+
user_message = f"Here's the information on composting: {relevant_segment} {user_query}"
|
72 |
+
messages = [
|
73 |
+
{"role": "system", "content": system_message},
|
74 |
+
{"role": "user", "content": user_message}
|
75 |
+
]
|
76 |
+
|
77 |
+
# Generate the response
|
78 |
+
response = openai.ChatCompletion.create(
|
79 |
+
model="text-davinci-003",
|
80 |
+
messages=messages,
|
81 |
+
max_tokens=150,
|
82 |
+
temperature=0.2,
|
83 |
+
top_p=1
|
84 |
+
)
|
85 |
+
|
86 |
+
# Extract the generated text and confidence score
|
87 |
+
generated_text = response['choices'][0]['message']['content'].strip()
|
88 |
+
# Confidence score extraction may vary depending on the model and API response structure
|
89 |
+
confidence_score = response['choices'][0].get('logprobs', {}).get('token_logprobs', [None])[0]
|
90 |
+
|
91 |
+
return generated_text, confidence_score
|
92 |
+
|
93 |
+
except Exception as e:
|
94 |
+
print(f"Error in generating response: {e}")
|
95 |
+
return f"Error in generating response: {e}"
|
96 |
+
|
97 |
+
'''
|
98 |
try:
|
99 |
system_message = "You are a chatbot specialized in providing information about food composting tips, tricks, and basics."
|
100 |
user_message = f"Here's the information on composting: {relevant_segment}"
|
|
|
115 |
except Exception as e:
|
116 |
print(f"Error in generating response: {e}")
|
117 |
return f"Error in generating response: {e}"
|
118 |
+
'''
|
119 |
|
120 |
|
121 |
def query_model(question):
|
|
|
150 |
|
151 |
# Define the HTML iframe content
|
152 |
iframe = '''
|
153 |
+
<div style="height:15px;"></div>
|
154 |
<iframe style="border-radius:12px"
|
155 |
src="https://open.spotify.com/embed/episode/1Emjgqf8PfwD42kvyKvtfW?utm_source=generator&theme=0"
|
156 |
width="100%" height="152" frameBorder="0"
|