Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,6 +3,7 @@ import gradio as gr
|
|
| 3 |
import requests
|
| 4 |
import inspect
|
| 5 |
import pandas as pd
|
|
|
|
| 6 |
|
| 7 |
# (Keep Constants as is)
|
| 8 |
# --- Constants ---
|
|
@@ -10,15 +11,75 @@ 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 |
def run_and_submit_all( profile: gr.OAuthProfile | None):
|
| 23 |
"""
|
| 24 |
Fetches all questions, runs the BasicAgent on them, submits all answers,
|
|
|
|
| 3 |
import requests
|
| 4 |
import inspect
|
| 5 |
import pandas as pd
|
| 6 |
+
import json
|
| 7 |
|
| 8 |
# (Keep Constants as is)
|
| 9 |
# --- Constants ---
|
|
|
|
| 11 |
|
| 12 |
# --- Basic Agent Definition ---
|
| 13 |
# ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
|
| 21 |
class BasicAgent:
|
| 22 |
def __init__(self):
|
| 23 |
+
|
| 24 |
+
|
| 25 |
print("BasicAgent initialized.")
|
| 26 |
def __call__(self, question: str) -> str:
|
| 27 |
print(f"Agent received question (first 50 chars): {question[:50]}...")
|
| 28 |
+
|
| 29 |
+
url = "https://api.fireworks.ai/inference/v1/chat/completions"
|
| 30 |
+
payload = {
|
| 31 |
+
"model": "accounts/fireworks/models/qwen2p5-vl-32b-instruct",
|
| 32 |
+
"max_tokens": 16000,
|
| 33 |
+
"top_p": 1,
|
| 34 |
+
"top_k": 40,
|
| 35 |
+
"presence_penalty": 0,
|
| 36 |
+
"frequency_penalty": 0,
|
| 37 |
+
"temperature": 0.6,
|
| 38 |
+
"messages": [
|
| 39 |
+
{
|
| 40 |
+
"role": "user",
|
| 41 |
+
"content": [
|
| 42 |
+
{
|
| 43 |
+
"type": "text",
|
| 44 |
+
"text": f"{question}"
|
| 45 |
+
},
|
| 46 |
+
{
|
| 47 |
+
"type": "image_url",
|
| 48 |
+
"image_url": {
|
| 49 |
+
"url": "https://images.unsplash.com/photo-1582538885592-e70a5d7ab3d3?ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D&auto=format&fit=crop&w=1770&q=80"
|
| 50 |
+
}
|
| 51 |
+
}
|
| 52 |
+
]
|
| 53 |
+
}
|
| 54 |
+
]
|
| 55 |
+
}
|
| 56 |
+
headers = {
|
| 57 |
+
"Accept": "application/json",
|
| 58 |
+
"Content-Type": "application/json",
|
| 59 |
+
"Authorization": "Bearer fw_3ZPv4AcKwgEBJT8p3KugTCm8"
|
| 60 |
+
}
|
| 61 |
+
requests.request("POST", url, headers=headers, data=json.dumps(payload))
|
| 62 |
+
|
| 63 |
+
|
| 64 |
+
|
| 65 |
+
|
| 66 |
+
|
| 67 |
+
|
| 68 |
fixed_answer = "This is a default answer."
|
| 69 |
+
|
| 70 |
+
|
| 71 |
+
|
| 72 |
+
|
| 73 |
+
|
| 74 |
+
|
| 75 |
+
|
| 76 |
print(f"Agent returning fixed answer: {fixed_answer}")
|
| 77 |
return fixed_answer
|
| 78 |
|
| 79 |
+
|
| 80 |
+
|
| 81 |
+
|
| 82 |
+
|
| 83 |
def run_and_submit_all( profile: gr.OAuthProfile | None):
|
| 84 |
"""
|
| 85 |
Fetches all questions, runs the BasicAgent on them, submits all answers,
|