Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,6 +4,9 @@ import requests
|
|
| 4 |
import pytz
|
| 5 |
import yaml
|
| 6 |
from tools.final_answer import FinalAnswerTool
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
from Gradio_UI import GradioUI
|
| 9 |
|
|
@@ -18,6 +21,48 @@ def my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return
|
|
| 18 |
"""
|
| 19 |
return "What magic will you build ?"
|
| 20 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
@tool
|
| 22 |
def get_current_time_in_timezone(timezone: str) -> str:
|
| 23 |
"""A tool that fetches the current local time in a specified timezone.
|
|
|
|
| 4 |
import pytz
|
| 5 |
import yaml
|
| 6 |
from tools.final_answer import FinalAnswerTool
|
| 7 |
+
from typing import List
|
| 8 |
+
import re
|
| 9 |
+
from pymatgen.core.composition import Composition
|
| 10 |
|
| 11 |
from Gradio_UI import GradioUI
|
| 12 |
|
|
|
|
| 21 |
"""
|
| 22 |
return "What magic will you build ?"
|
| 23 |
|
| 24 |
+
@tool
|
| 25 |
+
def extract_elements_and_formula(text: str) -> str:
|
| 26 |
+
"""A tool that extracts valid chemical formulas and their elements from a string of text.
|
| 27 |
+
|
| 28 |
+
Args:
|
| 29 |
+
text: A string possibly containing chemical formulas and element symbols (e.g., from titles or abstracts).
|
| 30 |
+
"""
|
| 31 |
+
# Regex to match potential formulas like Bi2Te3, Sb2Te3, NaCl, Al2O3, etc.
|
| 32 |
+
formula_pattern = r'\b(?:[A-Z][a-z]?[0-9]*){1,}\b'
|
| 33 |
+
|
| 34 |
+
raw_matches = re.findall(formula_pattern, text)
|
| 35 |
+
valid_formulas = []
|
| 36 |
+
all_elements = set()
|
| 37 |
+
|
| 38 |
+
for match in raw_matches:
|
| 39 |
+
try:
|
| 40 |
+
comp = Composition(match)
|
| 41 |
+
valid_formulas.append(match)
|
| 42 |
+
for el in comp.elements:
|
| 43 |
+
all_elements.add(el.symbol)
|
| 44 |
+
except Exception:
|
| 45 |
+
continue # Not a valid formula
|
| 46 |
+
|
| 47 |
+
if not valid_formulas:
|
| 48 |
+
return "No valid chemical formulas found in the input text."
|
| 49 |
+
|
| 50 |
+
return (
|
| 51 |
+
f"Extracted elements: {', '.join(sorted(all_elements))}\n"
|
| 52 |
+
f"Extracted formulas: {', '.join(sorted(set(valid_formulas)))}"
|
| 53 |
+
)
|
| 54 |
+
|
| 55 |
+
@tool
|
| 56 |
+
def search_materials_topic(query: str) -> str:
|
| 57 |
+
"""A tool that uses DuckDuckGo to search for recent materials science information on a given topic.
|
| 58 |
+
|
| 59 |
+
Args:
|
| 60 |
+
query: A short text query related to a material, technique, or research concept (e.g., 'high entropy alloys bandgap').
|
| 61 |
+
"""
|
| 62 |
+
search_tool = DuckDuckGoSearchTool()
|
| 63 |
+
results = search_tool.run(query)
|
| 64 |
+
return results
|
| 65 |
+
|
| 66 |
@tool
|
| 67 |
def get_current_time_in_timezone(timezone: str) -> str:
|
| 68 |
"""A tool that fetches the current local time in a specified timezone.
|