Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -38,7 +38,7 @@ def search_digikey_components(keywords: str) -> dict:
|
|
| 38 |
}
|
| 39 |
payload = {
|
| 40 |
"Keywords": keywords,
|
| 41 |
-
"Limit":
|
| 42 |
"Offset": 0,
|
| 43 |
"FilterOptionsRequest": {
|
| 44 |
"MarketPlaceFilter": "NoFilter",
|
|
@@ -65,10 +65,16 @@ def load_t5_model():
|
|
| 65 |
# Generate advice for a component
|
| 66 |
def generate_advice(product: dict, tokenizer, model) -> str:
|
| 67 |
description = product.get("Description", {}).get("DetailedDescription", "No description available.")
|
| 68 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 69 |
inputs = tokenizer.encode(prompt, return_tensors="pt", max_length=512, truncation=True)
|
| 70 |
-
outputs = model.generate(inputs, max_length=
|
| 71 |
advice = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
|
|
|
| 72 |
return advice
|
| 73 |
|
| 74 |
# Streamlit app interface
|
|
|
|
| 38 |
}
|
| 39 |
payload = {
|
| 40 |
"Keywords": keywords,
|
| 41 |
+
"Limit": 10,
|
| 42 |
"Offset": 0,
|
| 43 |
"FilterOptionsRequest": {
|
| 44 |
"MarketPlaceFilter": "NoFilter",
|
|
|
|
| 65 |
# Generate advice for a component
|
| 66 |
def generate_advice(product: dict, tokenizer, model) -> str:
|
| 67 |
description = product.get("Description", {}).get("DetailedDescription", "No description available.")
|
| 68 |
+
category = product.get("Category", {}).get("Name", "Unknown Category")
|
| 69 |
+
manufacturer = product.get("Manufacturer", {}).get("Name", "Unknown Manufacturer")
|
| 70 |
+
|
| 71 |
+
# Use multiple attributes for the prompt
|
| 72 |
+
prompt = f"Provide usage advice for the following electronic component. Description: {description}. Category: {category}. Manufacturer: {manufacturer}. Suggest other components that may work well with it."
|
| 73 |
+
|
| 74 |
inputs = tokenizer.encode(prompt, return_tensors="pt", max_length=512, truncation=True)
|
| 75 |
+
outputs = model.generate(inputs, max_length=150, num_beams=4, early_stopping=True)
|
| 76 |
advice = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 77 |
+
|
| 78 |
return advice
|
| 79 |
|
| 80 |
# Streamlit app interface
|