AsthanM commited on
Commit
5da62ea
·
verified ·
1 Parent(s): 1e11b8e

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +40 -0
app.py ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import requests
3
+ import os
4
+
5
+ API_URL = "https://api-inference.huggingface.co/models/meta-llama/Llama-3.3-70B-Instruct"
6
+ headers = {"Authorization": f"Bearer {os.getenv('HUGGINGFACE_API_KEY')}"}
7
+
8
+ def query_model(product1, product2):
9
+ prompt = f\"\"\"Compare the following two products or services:
10
+
11
+ Product/Service 1:
12
+ {product1}
13
+
14
+ Product/Service 2:
15
+ {product2}
16
+
17
+ Your task:
18
+ - Provide a detailed feature-by-feature comparison.
19
+ - Perform a SWOT analysis (Strengths, Weaknesses, Opportunities, Threats) for each.
20
+ - Highlight key differentiators and insights in a business-focused summary.
21
+ - Use markdown formatting (e.g., bold headings, bullet points) for readability.\"\"\"
22
+
23
+ response = requests.post(API_URL, headers=headers, json={"inputs": prompt})
24
+ result = response.json()
25
+ return result[0]['generated_text'] if isinstance(result, list) else str(result)
26
+
27
+ st.set_page_config(page_title="LLM Product Comparison", layout="wide")
28
+ st.title("📊 Product Comparison with Hugging Face LLM")
29
+
30
+ product1 = st.text_input("Product/Service 1", value="iPhone 13")
31
+ product2 = st.text_input("Product/Service 2", value="iPhone 14")
32
+
33
+ if st.button("Compare"):
34
+ if not product1 or not product2:
35
+ st.warning("Please enter both products.")
36
+ else:
37
+ with st.spinner("Generating comparison..."):
38
+ response = query_model(product1, product2)
39
+ st.markdown("### 📝 Comparison Result")
40
+ st.markdown(response)