Spaces:
Paused
Paused
Samuel Thomas
commited on
Commit
·
652c3df
1
Parent(s):
776e564
test
Browse files- app.py +24 -2
- mytools.py +0 -22
app.py
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from typing import TypedDict, Annotated
|
| 3 |
-
from huggingface_hub import InferenceClient, login
|
| 4 |
from langchain_huggingface import ChatHuggingFace, HuggingFaceEndpoint, HuggingFacePipeline
|
| 5 |
#from langchain.schema import AIMessage, HumanMessage
|
| 6 |
from langgraph.graph.message import add_messages
|
|
@@ -12,7 +12,7 @@ import datasets
|
|
| 12 |
import os
|
| 13 |
from langgraph.graph import START, StateGraph
|
| 14 |
from langchain.tools import Tool
|
| 15 |
-
from mytools import search_tool, weather_info_tool
|
| 16 |
#from dotenv import load_dotenv
|
| 17 |
|
| 18 |
#load_dotenv()
|
|
@@ -68,6 +68,28 @@ guest_info_tool = Tool(
|
|
| 68 |
description="Retrieves detailed information about gala guests based on their name or relation."
|
| 69 |
)
|
| 70 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 71 |
def predict(message, history):
|
| 72 |
# Convert Gradio history to LangChain message format
|
| 73 |
history_langchain_format = []
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from typing import TypedDict, Annotated
|
| 3 |
+
from huggingface_hub import InferenceClient, login, list_models
|
| 4 |
from langchain_huggingface import ChatHuggingFace, HuggingFaceEndpoint, HuggingFacePipeline
|
| 5 |
#from langchain.schema import AIMessage, HumanMessage
|
| 6 |
from langgraph.graph.message import add_messages
|
|
|
|
| 12 |
import os
|
| 13 |
from langgraph.graph import START, StateGraph
|
| 14 |
from langchain.tools import Tool
|
| 15 |
+
from mytools import search_tool, weather_info_tool
|
| 16 |
#from dotenv import load_dotenv
|
| 17 |
|
| 18 |
#load_dotenv()
|
|
|
|
| 68 |
description="Retrieves detailed information about gala guests based on their name or relation."
|
| 69 |
)
|
| 70 |
|
| 71 |
+
|
| 72 |
+
def get_hub_stats(author: str) -> str:
|
| 73 |
+
"""Fetches the most downloaded model from a specific author on the Hugging Face Hub."""
|
| 74 |
+
try:
|
| 75 |
+
# List models from the specified author, sorted by downloads
|
| 76 |
+
models = list(list_models(author=author, sort="downloads", direction=-1, limit=1))
|
| 77 |
+
|
| 78 |
+
if models:
|
| 79 |
+
model = models[0]
|
| 80 |
+
return f"The most downloaded model by {author} is {model.id} with {model.downloads:,} downloads."
|
| 81 |
+
else:
|
| 82 |
+
return f"No models found for author {author}."
|
| 83 |
+
except Exception as e:
|
| 84 |
+
return f"Error fetching models for {author}: {str(e)}"
|
| 85 |
+
|
| 86 |
+
# Initialize the tool
|
| 87 |
+
hub_stats_tool = Tool(
|
| 88 |
+
name="get_hub_stats",
|
| 89 |
+
func=get_hub_stats,
|
| 90 |
+
description="Fetches the most downloaded model from a specific author on the Hugging Face Hub."
|
| 91 |
+
)
|
| 92 |
+
|
| 93 |
def predict(message, history):
|
| 94 |
# Convert Gradio history to LangChain message format
|
| 95 |
history_langchain_format = []
|
mytools.py
CHANGED
|
@@ -1,7 +1,6 @@
|
|
| 1 |
from langchain.tools import Tool
|
| 2 |
from langchain_community.tools import DuckDuckGoSearchRun
|
| 3 |
import random
|
| 4 |
-
from huggingface_hub import list_models
|
| 5 |
|
| 6 |
|
| 7 |
search_tool = DuckDuckGoSearchRun()
|
|
@@ -25,24 +24,3 @@ weather_info_tool = Tool(
|
|
| 25 |
description="Fetches dummy weather information for a given location."
|
| 26 |
)
|
| 27 |
|
| 28 |
-
|
| 29 |
-
def get_hub_stats(author: str) -> str:
|
| 30 |
-
"""Fetches the most downloaded model from a specific author on the Hugging Face Hub."""
|
| 31 |
-
try:
|
| 32 |
-
# List models from the specified author, sorted by downloads
|
| 33 |
-
models = list(list_models(author=author, sort="downloads", direction=-1, limit=1))
|
| 34 |
-
|
| 35 |
-
if models:
|
| 36 |
-
model = models[0]
|
| 37 |
-
return f"The most downloaded model by {author} is {model.id} with {model.downloads:,} downloads."
|
| 38 |
-
else:
|
| 39 |
-
return f"No models found for author {author}."
|
| 40 |
-
except Exception as e:
|
| 41 |
-
return f"Error fetching models for {author}: {str(e)}"
|
| 42 |
-
|
| 43 |
-
# Initialize the tool
|
| 44 |
-
hub_stats_tool = Tool(
|
| 45 |
-
name="get_hub_stats",
|
| 46 |
-
func=get_hub_stats,
|
| 47 |
-
description="Fetches the most downloaded model from a specific author on the Hugging Face Hub."
|
| 48 |
-
)
|
|
|
|
| 1 |
from langchain.tools import Tool
|
| 2 |
from langchain_community.tools import DuckDuckGoSearchRun
|
| 3 |
import random
|
|
|
|
| 4 |
|
| 5 |
|
| 6 |
search_tool = DuckDuckGoSearchRun()
|
|
|
|
| 24 |
description="Fetches dummy weather information for a given location."
|
| 25 |
)
|
| 26 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|