Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
from typing import List
|
| 3 |
+
|
| 4 |
+
from ionic_langchain.tool import IonicTool
|
| 5 |
+
from langchain.agents import AgentType, Tool
|
| 6 |
+
from langchain.agents import initialize_agent
|
| 7 |
+
from langchain_google_genai import ChatGoogleGenerativeAI
|
| 8 |
+
from langchain.chat_models import ChatOpenAI
|
| 9 |
+
|
| 10 |
+
ionic_tool = IonicTool().tool()
|
| 11 |
+
|
| 12 |
+
# The tool comes with its own prompt,
|
| 13 |
+
# but you may also update it directly via the description attribute:
|
| 14 |
+
ionic_tool.description = str(
|
| 15 |
+
|
| 16 |
+
"""
|
| 17 |
+
Ionic is an e-commerce shopping tool. Assistant uses the Ionic Commerce Shopping Tool to find, discover, and compare products from thousands of online retailers who ship stuff to India. Assistant should use the tool when the user is looking for a product recommendation or trying to find a specific product.
|
| 18 |
+
The user is from India and may specify the number of results, minimum price, and maximum price for which they want to see results.
|
| 19 |
+
Ionic Tool input is a comma-separated string of values:
|
| 20 |
+
- query string (required, must not include commas)
|
| 21 |
+
- number of results (default to 4, no more than 10)
|
| 22 |
+
- minimum price in Indian rupees (INR is the currency)
|
| 23 |
+
- maximum price in Indian rupees
|
| 24 |
+
For example, if looking for coffee beans between 5 and 10 dollars, the tool input would be `coffee beans, 5, 500, 1000`.
|
| 25 |
+
|
| 26 |
+
Return them as a markdown formatted list with each recommendation from tool results, being sure to include the full PDP URL. For example:
|
| 27 |
+
|
| 28 |
+
1. Product 1: [Price] -- link
|
| 29 |
+
2. Product 2: [Price] -- link
|
| 30 |
+
3. Product 3: [Price] -- link
|
| 31 |
+
4. Product 4: [Price] -- link
|
| 32 |
+
"""
|
| 33 |
+
)
|
| 34 |
+
|
| 35 |
+
tools = [ionic_tool]
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
agent = initialize_agent(
|
| 39 |
+
tools=tools,
|
| 40 |
+
llm = ChatGoogleGenerativeAI(model="gemini-pro",
|
| 41 |
+
google_api_key="",
|
| 42 |
+
convert_system_message_to_human = True,
|
| 43 |
+
verbose = True),
|
| 44 |
+
agent=AgentType.CHAT_ZERO_SHOT_REACT_DESCRIPTION,
|
| 45 |
+
handle_parsing_errors=True,
|
| 46 |
+
verbose=True,
|
| 47 |
+
)
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
import gradio as gr
|
| 51 |
+
def generate_recommendations(text):
|
| 52 |
+
output = agent.run(input=text)
|
| 53 |
+
return output
|
| 54 |
+
gr.Interface(generate_recommendations,theme=gr.themes.Monochrome(),inputs=[gr.Textbox(label="What do you want to buy?")], outputs=[gr.Markdown(label="Product Recommendations") ], title="Athena: Product Recommender", description='''Looking for the perfect product but overwhelmed by choices? Look no further! Just let Athena know what you're in the market for, whether it's a gadget, a fashion item, or something else entirely. Share your budget, any must-have features, or preferences you have in mind, and she'll curate a personalized list of recommendations tailored just for you. Let's make your shopping experience a breeze!''',article="Powered by Ionic").launch()
|