Spaces:
Sleeping
Sleeping
barathm111
commited on
Commit
•
d3a54c8
1
Parent(s):
8462c29
Upload app.py
Browse files
app.py
CHANGED
@@ -31,36 +31,38 @@ def calculate_ranking(data):
|
|
31 |
institution["Rank"] = rank
|
32 |
return ranked_data
|
33 |
|
34 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
35 |
def chatbot_response(user_message):
|
|
|
36 |
if "rank" in user_message.lower():
|
37 |
-
# Example data for ranking
|
38 |
-
example_data = [
|
39 |
-
{"Institution": "A", "TLR": 70, "GO": 85, "OI": 90, "PR": 75},
|
40 |
-
{"Institution": "B", "TLR": 80, "GO": 88, "OI": 85, "PR": 90},
|
41 |
-
{"Institution": "C", "TLR": 65, "GO": 80, "OI": 70, "PR": 60},
|
42 |
-
]
|
43 |
ranked_data = calculate_ranking(example_data)
|
44 |
response = "Here are the ranks of the institutions:\n"
|
45 |
for institution in ranked_data:
|
46 |
response += f"Rank {institution['Rank']}: {institution['Institution']} (Total Score: {institution['Total']})\n"
|
47 |
return response
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
|
59 |
# Gradio interface
|
60 |
def build_gradio_ui():
|
61 |
with gr.Blocks() as demo:
|
62 |
-
gr.Markdown("## Chatbot with
|
63 |
-
gr.Markdown("
|
64 |
with gr.Row():
|
65 |
user_input = gr.Textbox(label="Your Message", placeholder="Type your message here...")
|
66 |
chatbot_output = gr.Textbox(label="Chatbot Response", interactive=False)
|
|
|
31 |
institution["Rank"] = rank
|
32 |
return ranked_data
|
33 |
|
34 |
+
# Predefined ranking data
|
35 |
+
example_data = [
|
36 |
+
{"Institution": "A", "TLR": 70, "GO": 85, "OI": 90, "PR": 75},
|
37 |
+
{"Institution": "B", "TLR": 80, "GO": 88, "OI": 85, "PR": 90},
|
38 |
+
{"Institution": "C", "TLR": 65, "GO": 80, "OI": 70, "PR": 60},
|
39 |
+
]
|
40 |
+
|
41 |
+
# Chatbot function
|
42 |
def chatbot_response(user_message):
|
43 |
+
# Check for predefined data queries
|
44 |
if "rank" in user_message.lower():
|
|
|
|
|
|
|
|
|
|
|
|
|
45 |
ranked_data = calculate_ranking(example_data)
|
46 |
response = "Here are the ranks of the institutions:\n"
|
47 |
for institution in ranked_data:
|
48 |
response += f"Rank {institution['Rank']}: {institution['Institution']} (Total Score: {institution['Total']})\n"
|
49 |
return response
|
50 |
+
|
51 |
+
# Fallback to model-generated response for out-of-scope questions
|
52 |
+
outputs = pipeline(
|
53 |
+
user_message,
|
54 |
+
max_new_tokens=100, # Restrict length for unexpected questions
|
55 |
+
do_sample=True,
|
56 |
+
temperature=0.7, # Slightly random responses for more natural output
|
57 |
+
top_p=0.9,
|
58 |
+
)
|
59 |
+
return outputs[0]["generated_text"]
|
60 |
|
61 |
# Gradio interface
|
62 |
def build_gradio_ui():
|
63 |
with gr.Blocks() as demo:
|
64 |
+
gr.Markdown("## Chatbot with Predefined Data and AI Responses")
|
65 |
+
gr.Markdown("Ask about institution rankings or any other general query!")
|
66 |
with gr.Row():
|
67 |
user_input = gr.Textbox(label="Your Message", placeholder="Type your message here...")
|
68 |
chatbot_output = gr.Textbox(label="Chatbot Response", interactive=False)
|