Update app.py
Browse files
app.py
CHANGED
|
@@ -20,14 +20,9 @@ def generate_main_question_gemini(paragraph: str):
|
|
| 20 |
|
| 21 |
try:
|
| 22 |
response = requests.post(
|
| 23 |
-
"https://router.huggingface.co/hf-inference/
|
| 24 |
headers={"Authorization": f"Bearer {API_KEY}"},
|
| 25 |
-
json={
|
| 26 |
-
"model": MODEL_NAME,
|
| 27 |
-
"messages": [
|
| 28 |
-
{"role": "user", "content": prompt}
|
| 29 |
-
]
|
| 30 |
-
}
|
| 31 |
)
|
| 32 |
|
| 33 |
if response.status_code != 200:
|
|
@@ -35,7 +30,11 @@ def generate_main_question_gemini(paragraph: str):
|
|
| 35 |
|
| 36 |
result = response.json()
|
| 37 |
|
| 38 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
|
| 40 |
except Exception as e:
|
| 41 |
return f"Error while connecting to API: {e}"
|
|
|
|
| 20 |
|
| 21 |
try:
|
| 22 |
response = requests.post(
|
| 23 |
+
f"https://router.huggingface.co/hf-inference/models/{MODEL_NAME}",
|
| 24 |
headers={"Authorization": f"Bearer {API_KEY}"},
|
| 25 |
+
json={"inputs": prompt}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
)
|
| 27 |
|
| 28 |
if response.status_code != 200:
|
|
|
|
| 30 |
|
| 31 |
result = response.json()
|
| 32 |
|
| 33 |
+
# أغلب موديلات HF بترجع لائحة، كل عنصر فيه "generated_text"
|
| 34 |
+
if isinstance(result, list):
|
| 35 |
+
return result[0].get("generated_text", "").strip()
|
| 36 |
+
|
| 37 |
+
return "Unexpected response format."
|
| 38 |
|
| 39 |
except Exception as e:
|
| 40 |
return f"Error while connecting to API: {e}"
|