fschwartzer commited on
Commit
17a40a4
1 Parent(s): 12c16b3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -16
app.py CHANGED
@@ -38,7 +38,34 @@ def gemini(query):
38
 
39
  response = model.generate_content(prompt_parts)
40
  return response.text
41
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
42
 
43
  def fetch_data_to_dataframe(query, limit=50, source="mercadolibre", token=None):
44
  if source == "mercadolibre":
@@ -53,30 +80,17 @@ def fetch_data_to_dataframe(query, limit=50, source="mercadolibre", token=None):
53
  df.columns = ['Title', 'Price', 'Currency', 'Condition', 'Link']
54
  else:
55
  df = pd.DataFrame()
56
- elif source == "amazon":
57
- df = fetch_amazon_data(query, token)
58
- elif source == "fipe":
59
- df = fetch_fipe_data(query, token)
60
  else:
61
  df = pd.DataFrame()
62
-
63
- # Process the DataFrame similarly for all sources if applicable
64
- # This is an example for MercadoLibre data; adjust processing as needed for other sources
65
  if not df.empty:
66
- # Additional processing here, like calculating z-scores, filtering, etc.
67
  pass
68
 
69
  return df
70
 
71
  def integrated_app(query):
72
- # Interpret the prompt using the Gemini model
73
- interpreted_response = gemini(query)
74
-
75
- refined_query = extract_refined_query(interpreted_response)
76
-
77
- # Fetch data from Mercado Livre based on the refined query
78
  df = fetch_data_to_dataframe(refined_query, 50, source="mercadolibre")
79
-
80
  if df.empty:
81
  return "No data found", pd.DataFrame()
82
  else:
 
38
 
39
  response = model.generate_content(prompt_parts)
40
  return response.text
41
+
42
+ def extract_refined_query(gemini_output):
43
+ """
44
+ Parses the Gemini model's output to extract a refined query for Mercado Livre.
45
+
46
+ Args:
47
+ - gemini_output (str): The output text from the Gemini model.
48
+
49
+ Returns:
50
+ - str: A refined query term extracted from the Gemini output.
51
+ """
52
+ # Placeholder for parsing logic. This should be replaced with actual parsing
53
+ # based on the structure of the Gemini model's output.
54
+ # For demonstration, let's assume the model's output is a descriptive text
55
+ # that includes keywords or phrases that can be used for a more focused search.
56
+
57
+ # Example parsing logic (simple and needs to be adapted):
58
+ # Assuming the output might contain phrases like "focus on [keyword] for best results"
59
+ # This is a very basic example and should be replaced with actual parsing logic.
60
+ refined_query = "default query" # Fallback query if parsing fails or finds no specific keywords
61
+
62
+ # Example: Search for a phrase indicating a refined query within the model's output
63
+ if "focus on" in gemini_output:
64
+ start_index = gemini_output.find("focus on") + len("focus on ")
65
+ end_index = gemini_output.find(" for best results", start_index)
66
+ refined_query = gemini_output[start_index:end_index] if end_index != -1 else gemini_output[start_index:start_index+20] # Extract the keyword or use a substring as a fallback
67
+
68
+ return refined_query
69
 
70
  def fetch_data_to_dataframe(query, limit=50, source="mercadolibre", token=None):
71
  if source == "mercadolibre":
 
80
  df.columns = ['Title', 'Price', 'Currency', 'Condition', 'Link']
81
  else:
82
  df = pd.DataFrame()
 
 
 
 
83
  else:
84
  df = pd.DataFrame()
 
 
 
85
  if not df.empty:
 
86
  pass
87
 
88
  return df
89
 
90
  def integrated_app(query):
91
+ gemini_output = gemini(query)
92
+ refined_query = extract_refined_query(gemini_output)
 
 
 
 
93
  df = fetch_data_to_dataframe(refined_query, 50, source="mercadolibre")
 
94
  if df.empty:
95
  return "No data found", pd.DataFrame()
96
  else: