Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,5 +1,7 @@
|
|
1 |
import gradio as gr
|
2 |
from sentence_transformers import SentenceTransformer, util
|
|
|
|
|
3 |
import openai
|
4 |
import os
|
5 |
|
@@ -60,10 +62,16 @@ def find_relevant_segment(user_query, segments):
|
|
60 |
|
61 |
def generate_response(user_query, relevant_segment):
|
62 |
"""
|
63 |
-
Generate a response emphasizing the bot's capability
|
64 |
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
65 |
try:
|
66 |
-
system_message = "You are a
|
67 |
user_message = f"Here's the information on composting: {relevant_segment}"
|
68 |
messages = [
|
69 |
{"role": "system", "content": system_message},
|
@@ -83,6 +91,8 @@ def generate_response(user_query, relevant_segment):
|
|
83 |
print(f"Error in generating response: {e}")
|
84 |
return f"Error in generating response: {e}"
|
85 |
|
|
|
|
|
86 |
def query_model(question):
|
87 |
"""
|
88 |
Process a question, find relevant information, and generate a response.
|
|
|
1 |
import gradio as gr
|
2 |
from sentence_transformers import SentenceTransformer, util
|
3 |
+
import transformers
|
4 |
+
from transformers import pipeline
|
5 |
import openai
|
6 |
import os
|
7 |
|
|
|
62 |
|
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 |
+
generator = pipeline("text-davinci-003", device=0)
|
68 |
+
response = generator(query=f"Here's the information on composting: {relevant_segment} {user_query}", max_length=150, temperature=0.2, top_p=1)
|
69 |
+
generated_text = response[0]['generated_text'].strip()
|
70 |
+
confidence_score = response[0]['score']
|
71 |
+
|
72 |
+
return generated_text, confidence_score
|
73 |
try:
|
74 |
+
system_message = "You are a chatbot specialized in providing information about food composting tips, tricks, and basics."
|
75 |
user_message = f"Here's the information on composting: {relevant_segment}"
|
76 |
messages = [
|
77 |
{"role": "system", "content": system_message},
|
|
|
91 |
print(f"Error in generating response: {e}")
|
92 |
return f"Error in generating response: {e}"
|
93 |
|
94 |
+
|
95 |
+
|
96 |
def query_model(question):
|
97 |
"""
|
98 |
Process a question, find relevant information, and generate a response.
|