Update app.py
Browse files
app.py
CHANGED
|
@@ -1,12 +1,5 @@
|
|
| 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
|
| 10 |
|
| 11 |
Product/Service 1:
|
| 12 |
{product1}
|
|
@@ -18,23 +11,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 |
-
|
| 31 |
-
|
|
|
|
| 32 |
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
response = query_model(product1, product2)
|
| 39 |
-
st.markdown("### 📝 Comparison Result")
|
| 40 |
-
st.markdown(response)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
def query_model(product1, product2):
|
| 2 |
+
prompt = f"""Compare the following two products or services:
|
| 3 |
|
| 4 |
Product/Service 1:
|
| 5 |
{product1}
|
|
|
|
| 11 |
- Provide a detailed feature-by-feature comparison.
|
| 12 |
- Perform a SWOT analysis (Strengths, Weaknesses, Opportunities, Threats) for each.
|
| 13 |
- Highlight key differentiators and insights in a business-focused summary.
|
| 14 |
+
- Use markdown formatting (e.g., bold headings, bullet points) for readability.
|
| 15 |
+
"""
|
| 16 |
|
| 17 |
response = requests.post(API_URL, headers=headers, json={"inputs": prompt})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
|
| 19 |
+
# 🐞 DEBUG: print API response info on screen
|
| 20 |
+
st.write("🧪 API Status Code:", response.status_code)
|
| 21 |
+
st.write("🧾 Raw Response:", response.text)
|
| 22 |
|
| 23 |
+
try:
|
| 24 |
+
result = response.json()
|
| 25 |
+
return result[0]['generated_text'] if isinstance(result, list) else str(result)
|
| 26 |
+
except Exception as e:
|
| 27 |
+
return f"⚠️ Error parsing response: {e}"
|
|
|
|
|
|
|
|
|