Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -12,7 +12,8 @@ import requests
|
|
| 12 |
import pandas as pd
|
| 13 |
|
| 14 |
from ddgs import DDGS
|
| 15 |
-
from
|
|
|
|
| 16 |
|
| 17 |
|
| 18 |
# =========================================================
|
|
@@ -21,7 +22,7 @@ from groq import Groq
|
|
| 21 |
|
| 22 |
DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
| 23 |
|
| 24 |
-
|
| 25 |
AUDIO_MODEL = "whisper-large-v3"
|
| 26 |
|
| 27 |
SYSTEM_PROMPT = """
|
|
@@ -44,16 +45,35 @@ Follow these rules:
|
|
| 44 |
# GROQ CLIENT
|
| 45 |
# =========================================================
|
| 46 |
|
| 47 |
-
def
|
| 48 |
-
api_key = os.getenv("
|
| 49 |
|
| 50 |
if not api_key:
|
| 51 |
raise RuntimeError(
|
| 52 |
-
"
|
| 53 |
"Hugging Face Space Settings > Variables and secrets."
|
| 54 |
)
|
| 55 |
|
| 56 |
-
return
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
|
| 58 |
|
| 59 |
# =========================================================
|
|
|
|
| 12 |
import pandas as pd
|
| 13 |
|
| 14 |
from ddgs import DDGS
|
| 15 |
+
from google import genai
|
| 16 |
+
from google.genai import types
|
| 17 |
|
| 18 |
|
| 19 |
# =========================================================
|
|
|
|
| 22 |
|
| 23 |
DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
| 24 |
|
| 25 |
+
GEMINI_MODEL = "gemini-3.5-flash-lite"
|
| 26 |
AUDIO_MODEL = "whisper-large-v3"
|
| 27 |
|
| 28 |
SYSTEM_PROMPT = """
|
|
|
|
| 45 |
# GROQ CLIENT
|
| 46 |
# =========================================================
|
| 47 |
|
| 48 |
+
def get_gemini_client():
|
| 49 |
+
api_key = os.getenv("GEMINI_API_KEY")
|
| 50 |
|
| 51 |
if not api_key:
|
| 52 |
raise RuntimeError(
|
| 53 |
+
"GEMINI_API_KEY is missing. Add it under "
|
| 54 |
"Hugging Face Space Settings > Variables and secrets."
|
| 55 |
)
|
| 56 |
|
| 57 |
+
return genai.Client(api_key=api_key)
|
| 58 |
+
|
| 59 |
+
|
| 60 |
+
def generate_gemini_response(prompt: str) -> str:
|
| 61 |
+
client = get_gemini_client()
|
| 62 |
+
|
| 63 |
+
response = client.models.generate_content(
|
| 64 |
+
model=GEMINI_MODEL,
|
| 65 |
+
contents=prompt,
|
| 66 |
+
config=types.GenerateContentConfig(
|
| 67 |
+
system_instruction=SYSTEM_PROMPT,
|
| 68 |
+
max_output_tokens=2048,
|
| 69 |
+
),
|
| 70 |
+
)
|
| 71 |
+
|
| 72 |
+
if not response.text:
|
| 73 |
+
raise RuntimeError("Gemini returned an empty response.")
|
| 74 |
+
|
| 75 |
+
return response.text.strip()
|
| 76 |
+
|
| 77 |
|
| 78 |
|
| 79 |
# =========================================================
|