Threatthriver commited on
Commit
51241b7
1 Parent(s): b6a8e71

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -7
app.py CHANGED
@@ -40,7 +40,6 @@ def respond(
40
  max_tokens: int,
41
  temperature: float,
42
  top_p: float,
43
- search_query: str = "" # Optional search query parameter for Yahoo scraping
44
  ) -> str:
45
  """
46
  Generates a response from the AI model based on the user's message, chat history, and optional Yahoo search results.
@@ -52,16 +51,21 @@ def respond(
52
  max_tokens (int): The maximum number of tokens for the output.
53
  temperature (float): Sampling temperature for controlling the randomness.
54
  top_p (float): Top-p (nucleus sampling) for controlling diversity.
55
- search_query (str): Optional search query to scrape Yahoo results from.
56
 
57
  Returns:
58
  str: The AI's response as it is generated, including the source URL if applicable.
59
  """
60
 
61
- # Scrape Yahoo search results if a query is provided
62
- if search_query:
63
- snippet, url = scrape_yahoo_search(search_query)
64
- message = f"{message}\n\nWeb Content:\n{snippet}\nSource: {url}"
 
 
 
 
 
 
65
 
66
  # Prepare the conversation history for the API call
67
  messages = [{"role": "system", "content": system_message}]
@@ -109,7 +113,6 @@ demo = gr.ChatInterface(
109
  step=0.05,
110
  label="Top-p (nucleus sampling)",
111
  ),
112
- gr.Textbox(value="", label="Yahoo Search Query (optional)", placeholder="Enter a search query")
113
  ],
114
  title="Chatbot Interface",
115
  description="A customizable chatbot interface using Hugging Face's Inference API with Yahoo search scraping capabilities.",
 
40
  max_tokens: int,
41
  temperature: float,
42
  top_p: float,
 
43
  ) -> str:
44
  """
45
  Generates a response from the AI model based on the user's message, chat history, and optional Yahoo search results.
 
51
  max_tokens (int): The maximum number of tokens for the output.
52
  temperature (float): Sampling temperature for controlling the randomness.
53
  top_p (float): Top-p (nucleus sampling) for controlling diversity.
 
54
 
55
  Returns:
56
  str: The AI's response as it is generated, including the source URL if applicable.
57
  """
58
 
59
+ # Check for trigger word and activate search feature if present
60
+ trigger_word = "search"
61
+ if trigger_word in message.lower():
62
+ # Extract the query from the message
63
+ query = message.lower().split(trigger_word, 1)[-1].strip()
64
+ if query:
65
+ snippet, url = scrape_yahoo_search(query)
66
+ message = f"{message}\n\nWeb Content:\n{snippet}\nSource: {url}"
67
+ else:
68
+ message = "Please provide a search query after the trigger word."
69
 
70
  # Prepare the conversation history for the API call
71
  messages = [{"role": "system", "content": system_message}]
 
113
  step=0.05,
114
  label="Top-p (nucleus sampling)",
115
  ),
 
116
  ],
117
  title="Chatbot Interface",
118
  description="A customizable chatbot interface using Hugging Face's Inference API with Yahoo search scraping capabilities.",