sophcheng commited on
Commit
a47a718
·
verified ·
1 Parent(s): 8049f79

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -11
app.py CHANGED
@@ -3,8 +3,8 @@ from sentence_transformers import SentenceTransformer, util
3
  import openai
4
  import os
5
  import random
6
- import transformers
7
- from transformers import pipeline
8
 
9
  os.environ["TOKENIZERS_PARALLELISM"] = "false"
10
 
@@ -96,17 +96,17 @@ def generate_response(user_query, relevant_segment):
96
  ai_int=random.randint(0,10)
97
  ai_helpers=["https://chatgpt.com/ - An AI chatbot","https://www.grammarly.com/ - Help with grammar and writing!","https://www.any.do/ - Creates a to do list to help you get your tasks completed!","https://scheduler.ai/- AI optimizes your schedule and works around pre-scheduled deadlines","ChatGPT Data Analyst - Helps you visualize and analize your data","ChatGPT Logo creator - Helps to create professional logos for companies or brands","ScholarGPT - Enhances your reaserch capabilities","ChatGPT's Math solver","Tutor Me by Khan Academy","Travel Guide by capchair - helps find destinations, plan trips, and manage budgets"]
98
  output_text=output_text+"\n\n Here is a helpful chatbot tool for you!: "+ ai_helpers[ai_int-1]
99
- #return output_text
100
 
101
  # Create pipeline for text generation with confidence scores
102
- generator = pipeline("text-davinci-003", device=0) # Adjust device if needed
103
 
104
  # Generate response and get confidence score
105
- response = generator(query=f"Here's the information on AI: {relevant_segment} {user_query}", max_length=150, temperature=0.2, top_p=1)
106
- generated_text = response[0]['generated_text'].strip()
107
- confidence_score = response[0]['score']
108
 
109
- return generated_text, confidence_score, output_text
110
 
111
  except Exception as e:
112
  print(f"Error in generating response: {e}")
@@ -155,9 +155,9 @@ with gr.Blocks(theme='JohnSmith9982/small_and_pretty') as demo:
155
  submit_button = gr.Button("Submit")
156
  submit_button.click(fn=query_model, inputs=question, outputs=answer)
157
 
158
- def display_response(question):
159
- response, confidence_score = query_model(question)
160
- answer.value = f"Response: {response}\nConfidence Score: {confidence_score:.2f}"
161
 
162
  #submit_button.click(fn=display_response, inputs=question, outputs=None)
163
 
 
3
  import openai
4
  import os
5
  import random
6
+ #import transformers
7
+ #from transformers import pipeline
8
 
9
  os.environ["TOKENIZERS_PARALLELISM"] = "false"
10
 
 
96
  ai_int=random.randint(0,10)
97
  ai_helpers=["https://chatgpt.com/ - An AI chatbot","https://www.grammarly.com/ - Help with grammar and writing!","https://www.any.do/ - Creates a to do list to help you get your tasks completed!","https://scheduler.ai/- AI optimizes your schedule and works around pre-scheduled deadlines","ChatGPT Data Analyst - Helps you visualize and analize your data","ChatGPT Logo creator - Helps to create professional logos for companies or brands","ScholarGPT - Enhances your reaserch capabilities","ChatGPT's Math solver","Tutor Me by Khan Academy","Travel Guide by capchair - helps find destinations, plan trips, and manage budgets"]
98
  output_text=output_text+"\n\n Here is a helpful chatbot tool for you!: "+ ai_helpers[ai_int-1]
99
+ return output_text
100
 
101
  # Create pipeline for text generation with confidence scores
102
+ #generator = pipeline("text-davinci-003", device=0) # Adjust device if needed
103
 
104
  # Generate response and get confidence score
105
+ #response = generator(query=f"Here's the information on AI: {relevant_segment} {user_query}", max_length=150, temperature=0.2, top_p=1)
106
+ #generated_text = response[0]['generated_text'].strip()
107
+ #confidence_score = response[0]['score']
108
 
109
+ #return generated_text, confidence_score, output_text
110
 
111
  except Exception as e:
112
  print(f"Error in generating response: {e}")
 
155
  submit_button = gr.Button("Submit")
156
  submit_button.click(fn=query_model, inputs=question, outputs=answer)
157
 
158
+ #def display_response(question):
159
+ #response, confidence_score = query_model(question)
160
+ #answer.value = f"Response: {response}\nConfidence Score: {confidence_score:.2f}"
161
 
162
  #submit_button.click(fn=display_response, inputs=question, outputs=None)
163