liang-huggingface commited on
Commit
ef0f098
·
1 Parent(s): 3800e81

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -23
app.py CHANGED
@@ -10,10 +10,9 @@ HF_API = os.getenv('HF_API')
10
  from transformers import AutoModelForCausalLM, AutoTokenizer
11
  import torch
12
 
13
- if False:
14
- # Load the model and tokenizer
15
- tokenizer = AutoTokenizer.from_pretrained("Qwen/Qwen-7B-Chat", trust_remote_code=True)
16
- model = AutoModelForCausalLM.from_pretrained("Qwen/Qwen-7B-Chat", device_map="auto",trust_remote_code=True).eval()
17
 
18
  def generate_summary(prompt):
19
  # Add instructions to the prompt to signal that you want a summary
@@ -64,7 +63,7 @@ def search_pubmed(query, retmax):
64
  return pd.DataFrame(article_list)
65
 
66
  # Function to summarize articles using Hugging Face's API
67
- def summarize_with_huggingface(model, selected_articles, USE_LOCAL=False):
68
  API_URL = f"https://api-inference.huggingface.co/models/{model}"
69
  # Your Hugging Face API key
70
  API_KEY = HF_API
@@ -121,8 +120,8 @@ def summarize_articles(indices, articles_for_display):
121
 
122
  PASSWORD = "pass"
123
 
124
- def check_password(password):
125
- if password == PASSWORD:
126
  return True, "Welcome!"
127
  else:
128
  return False, "Incorrect username or password."
@@ -138,32 +137,30 @@ with gr.Blocks() as demo:
138
  login_button = gr.Button("Login")
139
  login_result = gr.Textbox(label="Login Result", interactive=False)
140
 
141
- # login_button.click(check_password, inputs=[username_input, password_input], outputs=[login_result])
142
 
143
- query_input = gr.Textbox(label="Query Keywords")
144
  with gr.Row():
145
- retmax_input = gr.Slider(minimum=1, maximum=20, value=5, step=1, label="Number of articles")
146
  model_input = gr.Textbox(label="Enter the model to use", value="h2oai/h2ogpt-4096-llama2-7b-chat")
147
- search_button = gr.Button("Search")
148
- output_table = gr.Dataframe(headers=["PMID", "Authors", "Title","Abstract" ])
149
- summarize_button = gr.Button("Summarize")
150
- summary_output = gr.Textbox()
 
 
151
 
152
- model_input.visible = False
153
- query_input.visible = False
154
- summarize_button.visible = False
155
 
156
  def process_login(is_success, message):
157
  if is_success:
158
  model_input.visible = True
159
- query_input.visible = True
160
  summarize_button.visible = True
161
- login_result.value = message
162
  login_result.visible = True
163
 
164
- login_button.click(check_password, inputs=[password_input], outputs=[login_result]).then(
165
- process_login, [login_result], []
166
- )
167
 
168
  def update_output_table(query, retmax):
169
  df = search_pubmed(query, retmax)
@@ -198,4 +195,4 @@ if False:
198
  outputs=summary_output
199
  )
200
 
201
- demo.launch(debug=True)
 
10
  from transformers import AutoModelForCausalLM, AutoTokenizer
11
  import torch
12
 
13
+ # Load the model and tokenizer
14
+ tokenizer = AutoTokenizer.from_pretrained("Qwen/Qwen-7B-Chat", trust_remote_code=True)
15
+ model = AutoModelForCausalLM.from_pretrained("Qwen/Qwen-7B-Chat", device_map="auto",trust_remote_code=True).eval()
 
16
 
17
  def generate_summary(prompt):
18
  # Add instructions to the prompt to signal that you want a summary
 
63
  return pd.DataFrame(article_list)
64
 
65
  # Function to summarize articles using Hugging Face's API
66
+ def summarize_with_huggingface(model, selected_articles, USE_LOCAL=True):
67
  API_URL = f"https://api-inference.huggingface.co/models/{model}"
68
  # Your Hugging Face API key
69
  API_KEY = HF_API
 
120
 
121
  PASSWORD = "pass"
122
 
123
+ def check_password(username, password):
124
+ if username == USERNAME and password == PASSWORD:
125
  return True, "Welcome!"
126
  else:
127
  return False, "Incorrect username or password."
 
137
  login_button = gr.Button("Login")
138
  login_result = gr.Textbox(label="Login Result", interactive=False)
139
 
140
+ login_button.click(check_password, inputs=[username_input, password_input], outputs=[login_result])
141
 
 
142
  with gr.Row():
 
143
  model_input = gr.Textbox(label="Enter the model to use", value="h2oai/h2ogpt-4096-llama2-7b-chat")
144
+ query_input = gr.Textbox(label="Query Keywords")
145
+ retmax_input = gr.Slider(minimum=1, maximum=20, value=5, step=1, label="Number of articles")
146
+ search_button = gr.Button("Search")
147
+ output_table = gr.Dataframe(headers=["PMID", "Authors", "Title","Abstract" ])
148
+ summarize_button = gr.Button("Summarize")
149
+ summary_output = gr.Textbox()
150
 
151
+ model_input.visible = False
152
+ query_input.visible = False
153
+ summarize_button.visible = False
154
 
155
  def process_login(is_success, message):
156
  if is_success:
157
  model_input.visible = True
158
+ query_button.visible = True
159
  summarize_button.visible = True
160
+ login_result.update(value=message)
161
  login_result.visible = True
162
 
163
+ login_button.click(check_password, inputs=[username_input, password_input], outputs=[process_login])
 
 
164
 
165
  def update_output_table(query, retmax):
166
  df = search_pubmed(query, retmax)
 
195
  outputs=summary_output
196
  )
197
 
198
+ demo.launch(auth=("user", "pass1234"), debug=True)