Shreyas094 commited on
Commit
3adaf66
·
verified ·
1 Parent(s): 1ce1b84

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -30
app.py CHANGED
@@ -23,21 +23,6 @@ import certifi
23
  from bs4 import BeautifulSoup
24
  import requests
25
 
26
-
27
- # List of available models
28
- AVAILABLE_MODELS = [
29
- "mistralai/Mistral-7B-Instruct-v0.1",
30
- "meta-llama/Llama-2-70b-chat-hf",
31
- "tiiuae/falcon-40b-instruct",
32
- "bigscience/bloomz",
33
- "google/flan-t5-xxl",
34
- "EleutherAI/gpt-neox-20b",
35
- "mistralai/Mistral-Nemo-Instruct-2407", # Current default model
36
- ]
37
-
38
- # Load environment variables from a .env file
39
- load_dotenv()
40
-
41
  # Load environment variables from a .env file
42
  load_dotenv()
43
 
@@ -51,10 +36,10 @@ SEARXNG_KEY = 'f9f07f93b37b8483aadb5ba717f556f3a4ac507b281b4ca01e6c6288aa3e3ae5'
51
 
52
  # Use the environment variable
53
  HF_TOKEN = os.getenv('HF_TOKEN')
54
-
55
- # Modify the client initialization to use the selected model
56
-
57
- client = InferenceClient(model_name, token=HF_TOKEN)
58
 
59
  # Initialize the similarity model
60
  similarity_model = SentenceTransformer('all-MiniLM-L6-v2')
@@ -326,7 +311,7 @@ Your response should be detailed, informative, accurate, and directly relevant t
326
  try:
327
  response = llm_client.chat_completion(
328
  messages=messages,
329
- max_tokens=10000,
330
  temperature=temperature
331
  )
332
  return response.choices[0].message.content.strip()
@@ -550,13 +535,9 @@ def search_and_scrape(query, chat_history, num_results=5, scraper="trafilatura",
550
  return f"An unexpected error occurred during the search and scrape process: {e}"
551
 
552
 
553
- # Update the chat_function to include the model selection
554
- def chat_function(message, history, num_results, scraper, max_chars, time_range, language, category, engines, safesearch, method, llm_temperature, model_name):
555
  chat_history = "\n".join([f"{role}: {msg}" for role, msg in history])
556
 
557
- # Get the client for the selected model
558
- client = client(model_name)
559
-
560
  response = search_and_scrape(
561
  query=message,
562
  chat_history=chat_history,
@@ -569,13 +550,11 @@ def chat_function(message, history, num_results, scraper, max_chars, time_range,
569
  engines=engines,
570
  safesearch=safesearch,
571
  method=method,
572
- llm_temperature=llm_temperature,
573
- client=client # Pass the client to the search_and_scrape function
574
  )
575
 
576
  yield response
577
 
578
- # Update the Gradio interface to include the model selection dropdown
579
  iface = gr.ChatInterface(
580
  chat_function,
581
  title="SearXNG Scraper for Financial News",
@@ -596,7 +575,6 @@ iface = gr.ChatInterface(
596
  gr.Slider(0, 2, value=2, step=1, label="Safe Search Level"),
597
  gr.Radio(["GET", "POST"], value="POST", label="HTTP Method"),
598
  gr.Slider(0, 1, value=0.2, step=0.1, label="LLM Temperature"),
599
- gr.Dropdown(AVAILABLE_MODELS, value="mistralai/Mistral-Nemo-Instruct-2407", label="Model Selection"),
600
  ],
601
  additional_inputs_accordion=gr.Accordion("⚙️ Advanced Parameters", open=True),
602
  retry_btn="Retry",
@@ -611,5 +589,5 @@ iface = gr.ChatInterface(
611
  )
612
 
613
  if __name__ == "__main__":
614
- logger.info("Starting the SearXNG Scraper for Financial News using ChatInterface with Advanced Parameters and Model Selection")
615
  iface.launch(share=True)
 
23
  from bs4 import BeautifulSoup
24
  import requests
25
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
26
  # Load environment variables from a .env file
27
  load_dotenv()
28
 
 
36
 
37
  # Use the environment variable
38
  HF_TOKEN = os.getenv('HF_TOKEN')
39
+ client = InferenceClient(
40
+ "meta-llama/Llama-3.1-8B-Instruct",
41
+ token=HF_TOKEN,
42
+ )
43
 
44
  # Initialize the similarity model
45
  similarity_model = SentenceTransformer('all-MiniLM-L6-v2')
 
311
  try:
312
  response = llm_client.chat_completion(
313
  messages=messages,
314
+ max_tokens=7000,
315
  temperature=temperature
316
  )
317
  return response.choices[0].message.content.strip()
 
535
  return f"An unexpected error occurred during the search and scrape process: {e}"
536
 
537
 
538
+ def chat_function(message, history, num_results, scraper, max_chars, time_range, language, category, engines, safesearch, method, llm_temperature):
 
539
  chat_history = "\n".join([f"{role}: {msg}" for role, msg in history])
540
 
 
 
 
541
  response = search_and_scrape(
542
  query=message,
543
  chat_history=chat_history,
 
550
  engines=engines,
551
  safesearch=safesearch,
552
  method=method,
553
+ llm_temperature=llm_temperature
 
554
  )
555
 
556
  yield response
557
 
 
558
  iface = gr.ChatInterface(
559
  chat_function,
560
  title="SearXNG Scraper for Financial News",
 
575
  gr.Slider(0, 2, value=2, step=1, label="Safe Search Level"),
576
  gr.Radio(["GET", "POST"], value="POST", label="HTTP Method"),
577
  gr.Slider(0, 1, value=0.2, step=0.1, label="LLM Temperature"),
 
578
  ],
579
  additional_inputs_accordion=gr.Accordion("⚙️ Advanced Parameters", open=True),
580
  retry_btn="Retry",
 
589
  )
590
 
591
  if __name__ == "__main__":
592
+ logger.info("Starting the SearXNG Scraper for Financial News using ChatInterface with Advanced Parameters")
593
  iface.launch(share=True)