Update app.py
Browse files
app.py
CHANGED
@@ -3,6 +3,8 @@ from sentence_transformers import SentenceTransformer, util
|
|
3 |
import openai
|
4 |
import os
|
5 |
import random
|
|
|
|
|
6 |
|
7 |
os.environ["TOKENIZERS_PARALLELISM"] = "false"
|
8 |
|
@@ -94,7 +96,17 @@ def generate_response(user_query, relevant_segment):
|
|
94 |
ai_int=random.randint(0,10)
|
95 |
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"]
|
96 |
output_text=output_text+"\n\n Here is a helpful chatbot tool for you!: "+ ai_helpers[ai_int-1]
|
97 |
-
return output_text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
98 |
|
99 |
except Exception as e:
|
100 |
print(f"Error in generating response: {e}")
|
|
|
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}")
|