Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,64 +1,130 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from huggingface_hub import InferenceClient
|
| 3 |
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
demo = gr.ChatInterface(
|
| 47 |
-
respond,
|
| 48 |
-
additional_inputs=[
|
| 49 |
-
gr.Textbox(value="You are a friendly Chatbot.", label="System message"),
|
| 50 |
-
gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
|
| 51 |
-
gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
|
| 52 |
-
gr.Slider(
|
| 53 |
-
minimum=0.1,
|
| 54 |
-
maximum=1.0,
|
| 55 |
-
value=0.95,
|
| 56 |
-
step=0.05,
|
| 57 |
-
label="Top-p (nucleus sampling)",
|
| 58 |
-
),
|
| 59 |
-
],
|
| 60 |
)
|
| 61 |
|
| 62 |
|
| 63 |
-
|
| 64 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from huggingface_hub import InferenceClient
|
| 3 |
|
| 4 |
+
from smolagents import CodeAgent, DuckDuckGoSearchTool, HfApiModel, load_tool, tool
|
| 5 |
+
import datetime
|
| 6 |
+
import requests
|
| 7 |
+
import pytz
|
| 8 |
+
import yaml
|
| 9 |
+
from tools.final_answer import FinalAnswerTool
|
| 10 |
+
|
| 11 |
+
from Gradio_UI import GradioUI
|
| 12 |
+
|
| 13 |
+
# Below is an example of a tool that does nothing. Amaze us with your creativity!
|
| 14 |
+
@tool
|
| 15 |
+
def my_custom_tool(arg1:str, arg2:int)-> str: # it's important to specify the return type
|
| 16 |
+
# Keep this format for the tool description / args description but feel free to modify the tool
|
| 17 |
+
"""A tool that does nothing yet
|
| 18 |
+
Args:
|
| 19 |
+
arg1: the first argument
|
| 20 |
+
arg2: the second argument
|
| 21 |
+
"""
|
| 22 |
+
return "What magic will you build ?"
|
| 23 |
+
|
| 24 |
+
@tool
|
| 25 |
+
def get_current_time_in_timezone(timezone: str) -> str:
|
| 26 |
+
"""A tool that fetches the current local time in a specified timezone.
|
| 27 |
+
Args:
|
| 28 |
+
timezone: A string representing a valid timezone (e.g., 'America/New_York').
|
| 29 |
+
"""
|
| 30 |
+
try:
|
| 31 |
+
# Create timezone object
|
| 32 |
+
tz = pytz.timezone(timezone)
|
| 33 |
+
# Get current time in that timezone
|
| 34 |
+
local_time = datetime.datetime.now(tz).strftime("%Y-%m-%d %H:%M:%S")
|
| 35 |
+
return f"The current local time in {timezone} is: {local_time}"
|
| 36 |
+
except Exception as e:
|
| 37 |
+
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
final_answer = FinalAnswerTool()
|
| 41 |
+
model = HfApiModel(
|
| 42 |
+
max_tokens=2096,
|
| 43 |
+
temperature=0.5,
|
| 44 |
+
model_id='Qwen/Qwen2.5-Coder-32B-Instruct',
|
| 45 |
+
custom_role_conversions=None,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
)
|
| 47 |
|
| 48 |
|
| 49 |
+
# Import tool from Hub
|
| 50 |
+
image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
|
| 51 |
+
|
| 52 |
+
with open("prompts.yaml", 'r') as stream:
|
| 53 |
+
prompt_templates = yaml.safe_load(stream)
|
| 54 |
+
|
| 55 |
+
agent = CodeAgent(
|
| 56 |
+
model=model,
|
| 57 |
+
tools=[final_answer], # add your tools here (don't remove final_answer)
|
| 58 |
+
max_steps=6,
|
| 59 |
+
verbosity_level=1,
|
| 60 |
+
grammar=None,
|
| 61 |
+
planning_interval=None,
|
| 62 |
+
name=None,
|
| 63 |
+
description=None,
|
| 64 |
+
prompt_templates=prompt_templates
|
| 65 |
+
)
|
| 66 |
+
|
| 67 |
+
|
| 68 |
+
GradioUI(agent).launch()
|
| 69 |
+
|
| 70 |
+
# """
|
| 71 |
+
# For more information on `huggingface_hub` Inference API support, please check the docs: https://huggingface.co/docs/huggingface_hub/v0.22.2/en/guides/inference
|
| 72 |
+
# """
|
| 73 |
+
# client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
|
| 74 |
+
|
| 75 |
+
|
| 76 |
+
# def respond(
|
| 77 |
+
# message,
|
| 78 |
+
# history: list[tuple[str, str]],
|
| 79 |
+
# system_message,
|
| 80 |
+
# max_tokens,
|
| 81 |
+
# temperature,
|
| 82 |
+
# top_p,
|
| 83 |
+
# ):
|
| 84 |
+
# messages = [{"role": "system", "content": system_message}]
|
| 85 |
+
|
| 86 |
+
# for val in history:
|
| 87 |
+
# if val[0]:
|
| 88 |
+
# messages.append({"role": "user", "content": val[0]})
|
| 89 |
+
# if val[1]:
|
| 90 |
+
# messages.append({"role": "assistant", "content": val[1]})
|
| 91 |
+
|
| 92 |
+
# messages.append({"role": "user", "content": message})
|
| 93 |
+
|
| 94 |
+
# response = ""
|
| 95 |
+
|
| 96 |
+
# for message in client.chat_completion(
|
| 97 |
+
# messages,
|
| 98 |
+
# max_tokens=max_tokens,
|
| 99 |
+
# stream=True,
|
| 100 |
+
# temperature=temperature,
|
| 101 |
+
# top_p=top_p,
|
| 102 |
+
# ):
|
| 103 |
+
# token = message.choices[0].delta.content
|
| 104 |
+
|
| 105 |
+
# response += token
|
| 106 |
+
# yield response
|
| 107 |
+
|
| 108 |
+
|
| 109 |
+
# """
|
| 110 |
+
# For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
|
| 111 |
+
# """
|
| 112 |
+
# demo = gr.ChatInterface(
|
| 113 |
+
# respond,
|
| 114 |
+
# additional_inputs=[
|
| 115 |
+
# gr.Textbox(value="You are a friendly Chatbot.", label="System message"),
|
| 116 |
+
# gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
|
| 117 |
+
# gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
|
| 118 |
+
# gr.Slider(
|
| 119 |
+
# minimum=0.1,
|
| 120 |
+
# maximum=1.0,
|
| 121 |
+
# value=0.95,
|
| 122 |
+
# step=0.05,
|
| 123 |
+
# label="Top-p (nucleus sampling)",
|
| 124 |
+
# ),
|
| 125 |
+
# ],
|
| 126 |
+
# )
|
| 127 |
+
|
| 128 |
+
|
| 129 |
+
# if __name__ == "__main__":
|
| 130 |
+
# demo.launch()
|