acecalisto3 commited on
Commit
adb910f
·
verified ·
1 Parent(s): 3633fc5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -8
app.py CHANGED
@@ -14,8 +14,7 @@ from huggingface_hub import InferenceClient
14
  # Check for Hugging Face API key
15
  api_key = os.getenv('access')
16
  if not api_key:
17
- print("Error: Hugging Face API key not found. Please set the 'access' environment variable.")
18
- exit(1)
19
 
20
  # Configure logging
21
  logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
@@ -96,24 +95,33 @@ def monitor_urls(storage_location, url1, url2, scrape_interval, content_type):
96
  driver.quit()
97
 
98
  # Define main function to handle user input
99
- def handle_input(storage_location, url1, url2, scrape_interval, content_type):
100
  global current_task, history
101
 
102
- current_task = f"Monitoring URLs: {url1}, {url2}"
103
- history.append(f"Task started: {current_task}")
104
- monitor_urls(storage_location, url1, url2, scrape_interval, content_type)
105
- return TASK_PROMPT.format(task=current_task, history="\n".join(history))
 
 
 
106
 
107
  # Define the chat response function
108
  client = InferenceClient("HuggingFaceH4/zephyr-7b-beta", token=api_key)
109
 
110
  def respond(
111
  message,
112
- history: list[tuple[str, str]],
113
  system_message,
114
  max_tokens,
115
  temperature,
116
  top_p,
 
 
 
 
 
 
117
  ):
118
  messages = [{"role": "system", "content": system_message}]
119
 
@@ -139,6 +147,9 @@ def respond(
139
  response += token
140
  yield response
141
 
 
 
 
142
  # Create Gradio interface
143
  demo = gr.ChatInterface(
144
  respond,
@@ -153,6 +164,7 @@ demo = gr.ChatInterface(
153
  step=0.05,
154
  label="Top-p (nucleus sampling)",
155
  ),
 
156
  gr.Textbox(value=default_file_path, label="Storage Location"),
157
  gr.Textbox(value="https://www.culver.k12.in.us/", label="URL 1"),
158
  gr.Textbox(value="https://www.facebook.com/CulverCommunitySchools", label="URL 2"),
 
14
  # Check for Hugging Face API key
15
  api_key = os.getenv('access')
16
  if not api_key:
17
+ raise EnvironmentError("Error: Hugging Face API key not found. Please set the 'access' environment variable.")
 
18
 
19
  # Configure logging
20
  logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
 
95
  driver.quit()
96
 
97
  # Define main function to handle user input
98
+ def handle_input(task, storage_location, url1, url2, scrape_interval, content_type):
99
  global current_task, history
100
 
101
+ if task == "Monitor URLs for Changes":
102
+ current_task = f"Monitoring URLs: {url1}, {url2}"
103
+ history.append(f"Task started: {current_task}")
104
+ monitor_urls(storage_location, url1, url2, scrape_interval, content_type)
105
+ return TASK_PROMPT.format(task=current_task, history="\n".join(history))
106
+ elif task == "Chat with a Friendly Chatbot":
107
+ return "You can chat with the friendly chatbot below."
108
 
109
  # Define the chat response function
110
  client = InferenceClient("HuggingFaceH4/zephyr-7b-beta", token=api_key)
111
 
112
  def respond(
113
  message,
114
+ history,
115
  system_message,
116
  max_tokens,
117
  temperature,
118
  top_p,
119
+ task,
120
+ storage_location,
121
+ url1,
122
+ url2,
123
+ scrape_interval,
124
+ content_type
125
  ):
126
  messages = [{"role": "system", "content": system_message}]
127
 
 
147
  response += token
148
  yield response
149
 
150
+ # Handle the selected task
151
+ handle_input(task, storage_location, url1, url2, scrape_interval, content_type)
152
+
153
  # Create Gradio interface
154
  demo = gr.ChatInterface(
155
  respond,
 
164
  step=0.05,
165
  label="Top-p (nucleus sampling)",
166
  ),
167
+ gr.Dropdown(choices=["Monitor URLs for Changes", "Chat with a Friendly Chatbot"], label="Select Task"),
168
  gr.Textbox(value=default_file_path, label="Storage Location"),
169
  gr.Textbox(value="https://www.culver.k12.in.us/", label="URL 1"),
170
  gr.Textbox(value="https://www.facebook.com/CulverCommunitySchools", label="URL 2"),