Spaces:
Sleeping
Sleeping
vighnesh-shetty-vs commited on
Commit ·
f55bc01
1
Parent(s): 742b3a2
Add updated files
Browse files
app.py
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
|
|
| 1 |
from transformers import pipeline
|
| 2 |
from game_data import calculate_impact
|
| 3 |
|
|
@@ -25,24 +26,32 @@ def classify_query(user_input):
|
|
| 25 |
|
| 26 |
return top_category, confidence_score
|
| 27 |
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
print(f"\nQuery: '{test_query}'")
|
| 33 |
-
|
| 34 |
-
category, confidence = classify_query(test_query)
|
| 35 |
-
print(f"Classification: {category} (Confidence: {confidence:.2f})")
|
| 36 |
|
| 37 |
-
|
| 38 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
|
| 44 |
-
|
| 45 |
-
|
| 46 |
|
| 47 |
-
|
| 48 |
-
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
from transformers import pipeline
|
| 3 |
from game_data import calculate_impact
|
| 4 |
|
|
|
|
| 26 |
|
| 27 |
return top_category, confidence_score
|
| 28 |
|
| 29 |
+
def process_query(user_input):
|
| 30 |
+
"""Processes the query for the Gradio interface."""
|
| 31 |
+
category, confidence = classify_query(user_input)
|
| 32 |
+
impact = calculate_impact(category, confidence, user_input)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
|
| 34 |
+
result_text = (
|
| 35 |
+
f"**Category:** {category}\n"
|
| 36 |
+
f"**Confidence:** {confidence:.2f}\n"
|
| 37 |
+
f"**Water Wasted:** {impact['water']}L\n"
|
| 38 |
+
f"**Energy Wasted:** {impact['energy']}kWh"
|
| 39 |
+
)
|
| 40 |
+
return result_text
|
| 41 |
|
| 42 |
+
# Create a basic Gradio interface to keep the Space alive
|
| 43 |
+
with gr.Blocks() as demo:
|
| 44 |
+
gr.Markdown("# 💧 EcoQueryQuest (Test UI)")
|
| 45 |
+
gr.Markdown("Type a query to see its hidden environmental cost!")
|
| 46 |
+
|
| 47 |
+
with gr.Row():
|
| 48 |
+
input_box = gr.Textbox(label="Your Query", placeholder="e.g., What is the capital of France?")
|
| 49 |
|
| 50 |
+
submit_btn = gr.Button("Analyze")
|
| 51 |
+
output_box = gr.Markdown(label="Impact Results")
|
| 52 |
|
| 53 |
+
submit_btn.click(fn=process_query, inputs=input_box, outputs=output_box)
|
| 54 |
+
|
| 55 |
+
# Launch the app so it stays running on Hugging Face
|
| 56 |
+
if __name__ == "__main__":
|
| 57 |
+
demo.launch()
|