SamarthPujari commited on
Commit
5736aa4
·
verified ·
1 Parent(s): a6ff792

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -21
app.py CHANGED
@@ -15,6 +15,12 @@ import torch
15
  # API Key for weather
16
  API_KEY = os.getenv("Weather_Token")
17
 
 
 
 
 
 
 
18
  # -------------------- TOOL 1: Get Weather --------------------
19
  @tool
20
  def get_current_weather(place: str) -> str:
@@ -108,27 +114,10 @@ def document_qna_tool(pdf_path: str, question: str) -> str:
108
  # -------------------- TOOL 4: Local Image Generation --------------------
109
  @tool
110
  def image_generator(prompt: str) -> str:
111
- """
112
- Generate an image from a given text prompt using Stable Diffusion.
113
-
114
- Args:
115
- prompt (str): Description of the image to generate.
116
-
117
- Returns:
118
- str: Path to the saved generated image.
119
- """
120
- try:
121
- device = "cuda" if torch.cuda.is_available() else "cpu"
122
- pipe = StableDiffusionPipeline.from_pretrained(
123
- "runwayml/stable-diffusion-v1-5",
124
- torch_dtype=torch.float16 if device == "cuda" else torch.float32
125
- ).to(device)
126
- image = pipe(prompt).images[0]
127
- output_path = "generated_image.png"
128
- image.save(output_path)
129
- return f"Image saved at {output_path}"
130
- except Exception as e:
131
- return f"Image generation failed: {str(e)}"
132
 
133
  # -------------------- Local LLM (Replaces HfApiModel) --------------------
134
  from transformers import pipeline
 
15
  # API Key for weather
16
  API_KEY = os.getenv("Weather_Token")
17
 
18
+ device = "cuda" if torch.cuda.is_available() else "cpu"
19
+ sd_pipe = StableDiffusionPipeline.from_pretrained(
20
+ "runwayml/stable-diffusion-v1-5",
21
+ torch_dtype=torch.float16 if device == "cuda" else torch.float32
22
+ ).to(device)
23
+
24
  # -------------------- TOOL 1: Get Weather --------------------
25
  @tool
26
  def get_current_weather(place: str) -> str:
 
114
  # -------------------- TOOL 4: Local Image Generation --------------------
115
  @tool
116
  def image_generator(prompt: str) -> str:
117
+ image = sd_pipe(prompt).images[0]
118
+ output_path = "generated_image.png"
119
+ image.save(output_path)
120
+ return f"Image saved at {output_path}"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
121
 
122
  # -------------------- Local LLM (Replaces HfApiModel) --------------------
123
  from transformers import pipeline