Spaces:
Runtime error
Runtime error
fixing
Browse files
app.py
CHANGED
@@ -1,9 +1,10 @@
|
|
1 |
import os
|
|
|
2 |
import gradio as gr
|
3 |
import requests
|
4 |
import inspect
|
5 |
import pandas as pd
|
6 |
-
from smolagents import CodeAgent
|
7 |
from smolagents.tools import DuckDuckGoSearchTool, PythonInterpreterTool
|
8 |
import json
|
9 |
import tempfile
|
@@ -13,6 +14,21 @@ from pathlib import Path
|
|
13 |
# --- Constants ---
|
14 |
DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
15 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
16 |
# --- Custom Tools ---
|
17 |
class SerperSearchTool:
|
18 |
"""Enhanced search tool using Serper API for more reliable results"""
|
|
|
1 |
import os
|
2 |
+
from transformers import pipeline
|
3 |
import gradio as gr
|
4 |
import requests
|
5 |
import inspect
|
6 |
import pandas as pd
|
7 |
+
from smolagents import CodeAgent
|
8 |
from smolagents.tools import DuckDuckGoSearchTool, PythonInterpreterTool
|
9 |
import json
|
10 |
import tempfile
|
|
|
14 |
# --- Constants ---
|
15 |
DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
16 |
|
17 |
+
|
18 |
+
|
19 |
+
class HfApiModel:
|
20 |
+
"""
|
21 |
+
Simple wrapper for Hugging Face pipeline as a replacement for smolagents.HfApiModel
|
22 |
+
"""
|
23 |
+
def __init__(self, model_id: str, token: str = None):
|
24 |
+
self.model_id = model_id
|
25 |
+
self.token = token or os.getenv("HUGGINGFACE_INFERENCE_TOKEN")
|
26 |
+
self.pipe = pipeline("text-generation", model=model_id, token=self.token)
|
27 |
+
|
28 |
+
def __call__(self, prompt: str) -> str:
|
29 |
+
outputs = self.pipe(prompt, max_new_tokens=512, do_sample=True)
|
30 |
+
return outputs[0]["generated_text"]
|
31 |
+
|
32 |
# --- Custom Tools ---
|
33 |
class SerperSearchTool:
|
34 |
"""Enhanced search tool using Serper API for more reliable results"""
|