DenverJones commited on
Commit
f2aa8b1
·
verified ·
1 Parent(s): fb48495

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -40
app.py CHANGED
@@ -1,25 +1,23 @@
1
- from smolagents import CodeAgent, DuckDuckGoSearchTool, HfApiModel, load_tool, tool
2
- import datetime
3
- import pytz
4
- import yaml
5
- from tools.final_answer import FinalAnswerTool
6
- from Gradio_UI import GradioUI
7
  from huggingface_hub import InferenceClient
8
 
9
- # Initialize Inference Client globally
10
- client = InferenceClient(repo_id="stabilityai/stable-diffusion-xl-base-1.0")
11
 
12
  @tool
13
  def generate_image(description: str) -> str:
14
  """
15
  Generates an image based on the given text description.
16
  Args:
17
- description (str): The text description of the image to generate.
18
  Returns:
19
  str: A URL to the generated image.
20
  """
21
  try:
22
- result = client.text_to_image(prompt=description)
 
 
 
 
23
  if 'url' in result[0]:
24
  return f"Here's your generated image: {result[0]['url']}"
25
  else:
@@ -27,33 +25,3 @@ def generate_image(description: str) -> str:
27
  except Exception as e:
28
  return f"Error generating image: {str(e)}"
29
 
30
- @tool
31
- def get_current_time_in_timezone(timezone: str) -> str:
32
- """Fetches the current local time in a specified timezone."""
33
- try:
34
- tz = pytz.timezone(timezone)
35
- local_time = datetime.datetime.now(tz).strftime("%Y-%m-%d %H:%M:%S")
36
- return f"The current local time in {timezone} is: {local_time}"
37
- except Exception as e:
38
- return f"Error fetching time for timezone '{timezone}': {str(e)}"
39
-
40
- # Initialize tools and agent
41
- final_answer = FinalAnswerTool()
42
- model = HfApiModel(
43
- max_tokens=2096,
44
- temperature=0.5,
45
- model_id='https://wxknx1kg971u7k1n.us-east-1.aws.endpoints.huggingface.cloud'
46
- )
47
-
48
- with open("prompts.yaml", 'r') as stream:
49
- prompt_templates = yaml.safe_load(stream)
50
-
51
- agent = CodeAgent(
52
- model=model,
53
- tools=[final_answer, generate_image],
54
- max_steps=6,
55
- verbosity_level=1,
56
- prompt_templates=prompt_templates
57
- )
58
-
59
- GradioUI(agent).launch()
 
 
 
 
 
 
 
1
  from huggingface_hub import InferenceClient
2
 
3
+ # Instantiate InferenceClient without 'repo_id'
4
+ client = InferenceClient()
5
 
6
  @tool
7
  def generate_image(description: str) -> str:
8
  """
9
  Generates an image based on the given text description.
10
  Args:
11
+ description (str): The text description of the image to generate.
12
  Returns:
13
  str: A URL to the generated image.
14
  """
15
  try:
16
+ # Specify the model explicitly when making the call
17
+ model_id = "stabilityai/stable-diffusion-xl-base-1.0"
18
+ result = client.text_to_image(model=model_id, prompt=description)
19
+
20
+ # Assuming the result contains a 'url' field
21
  if 'url' in result[0]:
22
  return f"Here's your generated image: {result[0]['url']}"
23
  else:
 
25
  except Exception as e:
26
  return f"Error generating image: {str(e)}"
27