vighnesh-shetty-vs commited on
Commit
f55bc01
·
1 Parent(s): 742b3a2

Add updated files

Browse files
Files changed (1) hide show
  1. app.py +26 -17
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
- # --- Testing Block (You can remove this when building the Gradio UI) ---
29
- if __name__ == "__main__":
30
- # Test 1: Simple Fact
31
- test_query = "What is the capital of France?"
32
- print(f"\nQuery: '{test_query}'")
33
-
34
- category, confidence = classify_query(test_query)
35
- print(f"Classification: {category} (Confidence: {confidence:.2f})")
36
 
37
- impact = calculate_impact(category, confidence, test_query)
38
- print(f"Impact: {impact['water']}L water, {impact['energy']}kWh energy")
 
 
 
 
 
39
 
40
- # Test 2: Creative Generation
41
- test_query_2 = "Write a 500-word sci-fi story about a robot who learns to love painting landscapes."
42
- print(f"\nQuery: '{test_query_2}'")
 
 
 
 
43
 
44
- category_2, confidence_2 = classify_query(test_query_2)
45
- print(f"Classification: {category_2} (Confidence: {confidence_2:.2f})")
46
 
47
- impact_2 = calculate_impact(category_2, confidence_2, test_query_2)
48
- print(f"Impact: {impact_2['water']}L water, {impact_2['energy']}kWh energy")
 
 
 
 
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()