Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -8,7 +8,7 @@ import random
|
|
| 8 |
import google.generativeai as genai
|
| 9 |
from nltk.corpus import stopwords
|
| 10 |
|
| 11 |
-
# --- CẤU HÌNH GEMINI
|
| 12 |
genai.configure(api_key="AIzaSyDmXGLBoweYkqyXMDtWwSWOKZCo6Exd4Dk")
|
| 13 |
|
| 14 |
# --- CẤU HÌNH STREAMLIT ---
|
|
@@ -41,13 +41,14 @@ def clean_text(series: pd.Series) -> pd.Series:
|
|
| 41 |
def explain_with_gemini(title: str, content: str, label: str):
|
| 42 |
try:
|
| 43 |
model = genai.GenerativeModel("gemini-pro")
|
|
|
|
| 44 |
prompt = f"""You are a news analysis expert.
|
| 45 |
Explain in detail why the following news article is classified as "{label}".
|
| 46 |
|
| 47 |
Title: {title}
|
| 48 |
Content: {content}
|
| 49 |
"""
|
| 50 |
-
response =
|
| 51 |
return response.text
|
| 52 |
except Exception as e:
|
| 53 |
return f"⚠️ Could not generate explanation: {e}"
|
|
|
|
| 8 |
import google.generativeai as genai
|
| 9 |
from nltk.corpus import stopwords
|
| 10 |
|
| 11 |
+
# --- CẤU HÌNH GEMINI ---
|
| 12 |
genai.configure(api_key="AIzaSyDmXGLBoweYkqyXMDtWwSWOKZCo6Exd4Dk")
|
| 13 |
|
| 14 |
# --- CẤU HÌNH STREAMLIT ---
|
|
|
|
| 41 |
def explain_with_gemini(title: str, content: str, label: str):
|
| 42 |
try:
|
| 43 |
model = genai.GenerativeModel("gemini-pro")
|
| 44 |
+
chat = model.start_chat()
|
| 45 |
prompt = f"""You are a news analysis expert.
|
| 46 |
Explain in detail why the following news article is classified as "{label}".
|
| 47 |
|
| 48 |
Title: {title}
|
| 49 |
Content: {content}
|
| 50 |
"""
|
| 51 |
+
response = chat.send_message(prompt)
|
| 52 |
return response.text
|
| 53 |
except Exception as e:
|
| 54 |
return f"⚠️ Could not generate explanation: {e}"
|