Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -9,34 +9,36 @@ from Gradio_UI import GradioUI
|
|
| 9 |
|
| 10 |
import wikipedia
|
| 11 |
|
|
|
|
| 12 |
@tool
|
| 13 |
def generate_image_from_wikipedia(topic: str) -> str:
|
| 14 |
"""
|
| 15 |
-
Fetches a Wikipedia summary of a given topic and
|
| 16 |
|
| 17 |
Args:
|
| 18 |
-
topic (str): The topic to search for
|
| 19 |
|
| 20 |
Returns:
|
| 21 |
-
str: URL or path to the generated image.
|
| 22 |
"""
|
| 23 |
try:
|
| 24 |
# Set Wikipedia language to Turkish
|
| 25 |
wikipedia.set_lang("tr")
|
| 26 |
-
|
| 27 |
# Get a short summary from Wikipedia
|
| 28 |
summary = wikipedia.summary(topic, sentences=2)
|
| 29 |
-
|
| 30 |
# Generate an image based on the summary
|
| 31 |
image = image_generation_tool(summary)
|
| 32 |
|
| 33 |
return image
|
| 34 |
-
|
| 35 |
except wikipedia.exceptions.DisambiguationError as e:
|
| 36 |
return f"Multiple topics found: {e.options[:5]}... Please specify further."
|
| 37 |
except wikipedia.exceptions.PageError:
|
| 38 |
return f"Sorry, no Wikipedia page was found for '{topic}'."
|
| 39 |
|
|
|
|
| 40 |
@tool
|
| 41 |
def get_current_time_in_timezone(timezone: str) -> str:
|
| 42 |
"""A tool that fetches the current local time in a specified timezone.
|
|
|
|
| 9 |
|
| 10 |
import wikipedia
|
| 11 |
|
| 12 |
+
@tool
|
| 13 |
@tool
|
| 14 |
def generate_image_from_wikipedia(topic: str) -> str:
|
| 15 |
"""
|
| 16 |
+
Fetches a Wikipedia summary of a given topic and generates an image based on it.
|
| 17 |
|
| 18 |
Args:
|
| 19 |
+
topic (str): The topic to search for in Wikipedia. It should be a short phrase like "Albert Einstein" or "The Great Wall of China".
|
| 20 |
|
| 21 |
Returns:
|
| 22 |
+
str: A URL or path to the generated image.
|
| 23 |
"""
|
| 24 |
try:
|
| 25 |
# Set Wikipedia language to Turkish
|
| 26 |
wikipedia.set_lang("tr")
|
| 27 |
+
|
| 28 |
# Get a short summary from Wikipedia
|
| 29 |
summary = wikipedia.summary(topic, sentences=2)
|
| 30 |
+
|
| 31 |
# Generate an image based on the summary
|
| 32 |
image = image_generation_tool(summary)
|
| 33 |
|
| 34 |
return image
|
| 35 |
+
|
| 36 |
except wikipedia.exceptions.DisambiguationError as e:
|
| 37 |
return f"Multiple topics found: {e.options[:5]}... Please specify further."
|
| 38 |
except wikipedia.exceptions.PageError:
|
| 39 |
return f"Sorry, no Wikipedia page was found for '{topic}'."
|
| 40 |
|
| 41 |
+
|
| 42 |
@tool
|
| 43 |
def get_current_time_in_timezone(timezone: str) -> str:
|
| 44 |
"""A tool that fetches the current local time in a specified timezone.
|