Update app.py
Browse files
app.py
CHANGED
|
@@ -4,21 +4,7 @@ import requests
|
|
| 4 |
import inspect
|
| 5 |
import pandas as pd
|
| 6 |
|
| 7 |
-
import
|
| 8 |
-
from transformers import (
|
| 9 |
-
pipeline,
|
| 10 |
-
AutoModelForCausalLM,
|
| 11 |
-
AutoTokenizer,
|
| 12 |
-
BlenderbotForConditionalGeneration,
|
| 13 |
-
BlenderbotTokenizer
|
| 14 |
-
)
|
| 15 |
-
import torch
|
| 16 |
-
print(f"PyTorch version: {torch.__version__}")
|
| 17 |
-
print(f"CUDA available: {torch.cuda.is_available()}")
|
| 18 |
-
print(f"GPU memory: {torch.cuda.get_device_properties(0).total_memory/1e9}GB" if torch.cuda.is_available() else "No GPU")
|
| 19 |
-
|
| 20 |
-
from typing import Optional
|
| 21 |
-
from huggingface_hub import InferenceClient
|
| 22 |
|
| 23 |
# (Keep Constants as is)
|
| 24 |
# --- Constants ---
|
|
@@ -41,7 +27,8 @@ from tools import (
|
|
| 41 |
|
| 42 |
class BasicAgent:
|
| 43 |
def __init__(self):
|
| 44 |
-
self.
|
|
|
|
| 45 |
|
| 46 |
def __call__(self, question, question_attach=""):
|
| 47 |
try:
|
|
@@ -54,22 +41,7 @@ class BasicAgent:
|
|
| 54 |
question = question[::-1]
|
| 55 |
print(f"Reversed question: {question}")
|
| 56 |
|
| 57 |
-
|
| 58 |
-
Answer the following question concisely and factually.
|
| 59 |
-
If you don't know, say "I don't know" rather than guessing.
|
| 60 |
-
</s>
|
| 61 |
-
<|user|>
|
| 62 |
-
{question}
|
| 63 |
-
</s>
|
| 64 |
-
<|assistant|>"""
|
| 65 |
-
|
| 66 |
-
response = self.client.text_generation(
|
| 67 |
-
prompt,
|
| 68 |
-
model="google/flan-t5-xxl",
|
| 69 |
-
max_new_tokens=100,
|
| 70 |
-
)
|
| 71 |
-
|
| 72 |
-
return response.strip()
|
| 73 |
|
| 74 |
except Exception as e:
|
| 75 |
print(f"Error: {str(e)}")
|
|
|
|
| 4 |
import inspect
|
| 5 |
import pandas as pd
|
| 6 |
|
| 7 |
+
from smolagents import DuckDuckGoSearchTool
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
|
| 9 |
# (Keep Constants as is)
|
| 10 |
# --- Constants ---
|
|
|
|
| 27 |
|
| 28 |
class BasicAgent:
|
| 29 |
def __init__(self):
|
| 30 |
+
self.search_tool = DuckDuckGoSearchTool()
|
| 31 |
+
|
| 32 |
|
| 33 |
def __call__(self, question, question_attach=""):
|
| 34 |
try:
|
|
|
|
| 41 |
question = question[::-1]
|
| 42 |
print(f"Reversed question: {question}")
|
| 43 |
|
| 44 |
+
self.search_tool(question)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
|
| 46 |
except Exception as e:
|
| 47 |
print(f"Error: {str(e)}")
|