krish10 commited on
Commit
ef2bd77
·
verified ·
1 Parent(s): 235e275

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -6
app.py CHANGED
@@ -16,15 +16,23 @@ TEMPERATURE = 0.1
16
  TOP_P = 0.9
17
 
18
  @spaces.GPU
19
- def respond_stream(title, abstract):
20
- if not title.strip() or not abstract.strip():
21
- return "❌ Error: Title and Abstract are required."
 
22
 
23
- prompt = f"Title: {title.strip()}\nAbstract: {abstract.strip()}"
 
 
 
 
 
24
 
 
25
  messages = [{"role": "user", "content": prompt}]
26
  prompt_text = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
27
 
 
28
  inputs = tokenizer(prompt_text, return_tensors="pt").to("cuda")
29
  streamer = TextIteratorStreamer(tokenizer, skip_prompt=True, skip_special_tokens=True)
30
 
@@ -48,9 +56,10 @@ def respond_stream(title, abstract):
48
 
49
  # Build Gradio interface
50
  with gr.Blocks() as demo:
51
- gr.Markdown("## 🤖 Qwen Streaming Chat — Medical Abstract Evaluator")
52
 
53
  with gr.Column():
 
54
  title = gr.Textbox(label="Title", lines=2, placeholder="Required")
55
  abstract = gr.Textbox(label="Abstract", lines=10, placeholder="Required")
56
 
@@ -59,7 +68,7 @@ with gr.Blocks() as demo:
59
 
60
  generate_btn.click(
61
  fn=respond_stream,
62
- inputs=[title, abstract],
63
  outputs=[output_box]
64
  )
65
 
 
16
  TOP_P = 0.9
17
 
18
  @spaces.GPU
19
+ def respond_stream(summary, title, abstract):
20
+ # Validate mandatory fields
21
+ if not summary.strip() or not title.strip() or not abstract.strip():
22
+ return "❌ Error: PICOS Summary, Title, and Abstract are all required."
23
 
24
+ # Build prompt
25
+ prompt = (
26
+ f"Instruction: Use the following PICOS summary to evaluate the abstract.\n"
27
+ f"\nPICOS Summary: {summary.strip()}"
28
+ f"\n\nTitle: {title.strip()}\nAbstract: {abstract.strip()}"
29
+ )
30
 
31
+ # Wrap into message for chat template
32
  messages = [{"role": "user", "content": prompt}]
33
  prompt_text = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
34
 
35
+ # Tokenize and prepare streamer
36
  inputs = tokenizer(prompt_text, return_tensors="pt").to("cuda")
37
  streamer = TextIteratorStreamer(tokenizer, skip_prompt=True, skip_special_tokens=True)
38
 
 
56
 
57
  # Build Gradio interface
58
  with gr.Blocks() as demo:
59
+ gr.Markdown("## 🤖 Qwen Streaming Chat — Abstract Evaluation with PICOS Summary")
60
 
61
  with gr.Column():
62
+ summary = gr.Textbox(label="PICOS Summary", lines=4, placeholder="Required")
63
  title = gr.Textbox(label="Title", lines=2, placeholder="Required")
64
  abstract = gr.Textbox(label="Abstract", lines=10, placeholder="Required")
65
 
 
68
 
69
  generate_btn.click(
70
  fn=respond_stream,
71
+ inputs=[summary, title, abstract],
72
  outputs=[output_box]
73
  )
74