sagar007 commited on
Commit
6c1f2d1
·
verified ·
1 Parent(s): 379919c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +3 -4
app.py CHANGED
@@ -32,7 +32,8 @@ Provide a concise answer in markdown format with citations [1], [2], etc."""
32
  @spaces.GPU(duration=120) # Allow up to 120 seconds of GPU time
33
  def generate_answer(prompt: str) -> str:
34
  """Generate a concise research answer using GPU."""
35
- response = generator(prompt, max_length=200, num_return_sequences=1, truncation=True)[0]["generated_text"]
 
36
  answer_start = response.find("Provide a concise") + len("Provide a concise answer in markdown format with citations [1], [2], etc.")
37
  return response[answer_start:].strip() if answer_start > -1 else "No detailed answer generated."
38
 
@@ -66,7 +67,7 @@ def process_deep_research(query: str, history: list):
66
  prompt = format_prompt(query, web_results)
67
  answer = generate_answer(prompt)
68
 
69
- # Convert tuple history to messages format (role/content)
70
  new_history = history + [{"role": "user", "content": query}, {"role": "assistant", "content": answer}]
71
 
72
  return answer, sources_html, new_history
@@ -174,7 +175,6 @@ with gr.Blocks(title="Deep Research Engine - ZeroGPU", css=css) as demo:
174
  answer, sources, new_history = process_deep_research(query, history)
175
  return answer, sources, new_history
176
 
177
- # Remove _js parameter from click event
178
  search_btn.click(
179
  fn=handle_search,
180
  inputs=[search_input, history_state],
@@ -185,7 +185,6 @@ with gr.Blocks(title="Deep Research Engine - ZeroGPU", css=css) as demo:
185
  outputs=[history_state]
186
  )
187
 
188
- # Remove _js parameter from submit event
189
  search_input.submit(
190
  fn=handle_search,
191
  inputs=[search_input, history_state],
 
32
  @spaces.GPU(duration=120) # Allow up to 120 seconds of GPU time
33
  def generate_answer(prompt: str) -> str:
34
  """Generate a concise research answer using GPU."""
35
+ # Use max_new_tokens instead of max_length to allow new token generation
36
+ response = generator(prompt, max_new_tokens=150, num_return_sequences=1, truncation=True)[0]["generated_text"]
37
  answer_start = response.find("Provide a concise") + len("Provide a concise answer in markdown format with citations [1], [2], etc.")
38
  return response[answer_start:].strip() if answer_start > -1 else "No detailed answer generated."
39
 
 
67
  prompt = format_prompt(query, web_results)
68
  answer = generate_answer(prompt)
69
 
70
+ # Convert history to messages format (role/content)
71
  new_history = history + [{"role": "user", "content": query}, {"role": "assistant", "content": answer}]
72
 
73
  return answer, sources_html, new_history
 
175
  answer, sources, new_history = process_deep_research(query, history)
176
  return answer, sources, new_history
177
 
 
178
  search_btn.click(
179
  fn=handle_search,
180
  inputs=[search_input, history_state],
 
185
  outputs=[history_state]
186
  )
187
 
 
188
  search_input.submit(
189
  fn=handle_search,
190
  inputs=[search_input, history_state],