Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,21 +3,43 @@ import gradio as gr
|
|
| 3 |
import requests
|
| 4 |
import inspect
|
| 5 |
import pandas as pd
|
| 6 |
-
|
| 7 |
# (Keep Constants as is)
|
| 8 |
# --- Constants ---
|
| 9 |
DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
| 10 |
|
| 11 |
# --- Basic Agent Definition ---
|
| 12 |
# ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
class BasicAgent:
|
| 14 |
def __init__(self):
|
| 15 |
-
print("
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
def __call__(self, question: str) -> str:
|
| 17 |
print(f"Agent received question (first 50 chars): {question[:50]}...")
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
|
| 22 |
def run_and_submit_all( profile: gr.OAuthProfile | None):
|
| 23 |
"""
|
|
|
|
| 3 |
import requests
|
| 4 |
import inspect
|
| 5 |
import pandas as pd
|
| 6 |
+
import google.generativeai as genai
|
| 7 |
# (Keep Constants as is)
|
| 8 |
# --- Constants ---
|
| 9 |
DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
| 10 |
|
| 11 |
# --- Basic Agent Definition ---
|
| 12 |
# ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
|
| 13 |
+
# class BasicAgent:
|
| 14 |
+
# def __init__(self):
|
| 15 |
+
# print("BasicAgent initialized.")
|
| 16 |
+
# def __call__(self, question: str) -> str:
|
| 17 |
+
# print(f"Agent received question (first 50 chars): {question[:50]}...")
|
| 18 |
+
# fixed_answer = "This is a default answer."
|
| 19 |
+
# print(f"Agent returning fixed answer: {fixed_answer}")
|
| 20 |
+
# return fixed_answer
|
| 21 |
+
|
| 22 |
class BasicAgent:
|
| 23 |
def __init__(self):
|
| 24 |
+
print("CustomAgent (using Gemini) initialized.")
|
| 25 |
+
|
| 26 |
+
# Setup Gemini API
|
| 27 |
+
genai.configure(api_key=os.environ.get("GEMINI_API_KEY"))
|
| 28 |
+
self.model = genai.GenerativeModel('gemini-pro')
|
| 29 |
+
|
| 30 |
def __call__(self, question: str) -> str:
|
| 31 |
print(f"Agent received question (first 50 chars): {question[:50]}...")
|
| 32 |
+
|
| 33 |
+
try:
|
| 34 |
+
response = self.model.generate_content(
|
| 35 |
+
f"Answer the following question clearly and concisely: {question}"
|
| 36 |
+
)
|
| 37 |
+
answer = response.text.strip()
|
| 38 |
+
print(f"Agent returning answer (first 100 chars): {answer[:100]}")
|
| 39 |
+
return answer
|
| 40 |
+
except Exception as e:
|
| 41 |
+
print(f"Error during Gemini API call: {e}")
|
| 42 |
+
return "Sorry, there was an error generating the answer."
|
| 43 |
|
| 44 |
def run_and_submit_all( profile: gr.OAuthProfile | None):
|
| 45 |
"""
|