dogutcu commited on
Commit
6077027
·
verified ·
1 Parent(s): 55fb31a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -1
app.py CHANGED
@@ -63,7 +63,6 @@ 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
- """
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,6 +83,16 @@ def generate_response(user_query, 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
 
89
  def query_model(question):
@@ -131,6 +140,15 @@ with gr.Blocks(theme='gradio/seafoam') as demo:
131
  submit_button = gr.Button("Submit")
132
  submit_button.click(fn=query_model, inputs=question, outputs=answer)
133
 
 
 
 
 
 
 
 
 
 
134
 
135
  # Launch the Gradio app to allow user interaction
136
  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
  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
  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):
 
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)