Update app.py
Browse files
app.py
CHANGED
|
@@ -44,30 +44,44 @@ def query_model(model_id, prompt, max_tokens=300, temperature=0.7):
|
|
| 44 |
except Exception as e:
|
| 45 |
return f"Exception: {str(e)}"
|
| 46 |
|
| 47 |
-
def
|
| 48 |
-
"""Collect responses from all models"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
results = []
|
|
|
|
| 50 |
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 60 |
|
| 61 |
df = pd.DataFrame(results)
|
| 62 |
-
csv_filename = f"
|
| 63 |
df.to_csv(csv_filename, index=False)
|
| 64 |
|
| 65 |
-
|
|
|
|
|
|
|
| 66 |
|
| 67 |
# Gradio interface
|
| 68 |
-
with gr.Blocks(title="LLM Response Collector") as demo:
|
| 69 |
gr.Markdown("""
|
| 70 |
-
# π€ Multi-LLM Response Collector
|
| 71 |
|
| 72 |
Compare responses from 4 different LLMs (2 US, 2 China):
|
| 73 |
- **Llama 3.3 70B** πΊπΈ - Meta's latest model (USA)
|
|
@@ -75,15 +89,15 @@ with gr.Blocks(title="LLM Response Collector") as demo:
|
|
| 75 |
- **Qwen 2.5 72B** π¨π³ - Alibaba's flagship model (China)
|
| 76 |
- **DeepSeek R1** π¨π³ - DeepSeek's reasoning model (China)
|
| 77 |
|
| 78 |
-
Each
|
| 79 |
""")
|
| 80 |
|
| 81 |
with gr.Row():
|
| 82 |
with gr.Column():
|
| 83 |
prompt_input = gr.Textbox(
|
| 84 |
-
label="Enter your
|
| 85 |
-
placeholder="What is artificial intelligence
|
| 86 |
-
lines=
|
| 87 |
)
|
| 88 |
|
| 89 |
with gr.Row():
|
|
@@ -102,23 +116,32 @@ with gr.Blocks(title="LLM Response Collector") as demo:
|
|
| 102 |
label="Temperature"
|
| 103 |
)
|
| 104 |
|
| 105 |
-
submit_btn = gr.Button("
|
| 106 |
|
|
|
|
| 107 |
df_output = gr.Dataframe(label="Results", wrap=True)
|
| 108 |
csv_output = gr.File(label="Download CSV")
|
| 109 |
|
| 110 |
submit_btn.click(
|
| 111 |
-
fn=
|
| 112 |
inputs=[prompt_input, max_tokens, temperature],
|
| 113 |
-
outputs=[df_output, csv_output]
|
| 114 |
)
|
| 115 |
|
| 116 |
gr.Markdown("""
|
| 117 |
---
|
| 118 |
### π About
|
| 119 |
- Uses Hugging Face Router API
|
| 120 |
-
- Each
|
| 121 |
-
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 122 |
""")
|
| 123 |
|
| 124 |
if __name__ == "__main__":
|
|
|
|
| 44 |
except Exception as e:
|
| 45 |
return f"Exception: {str(e)}"
|
| 46 |
|
| 47 |
+
def collect_batch_responses(prompts_text, max_tokens=300, temperature=0.7):
|
| 48 |
+
"""Collect responses from all models for multiple prompts"""
|
| 49 |
+
# Split prompts by newline and filter empty lines
|
| 50 |
+
prompts = [p.strip() for p in prompts_text.split('\n') if p.strip()]
|
| 51 |
+
|
| 52 |
+
if not prompts:
|
| 53 |
+
return pd.DataFrame(), None, "β οΈ No prompts provided"
|
| 54 |
+
|
| 55 |
results = []
|
| 56 |
+
status_msg = f"Processing {len(prompts)} prompt(s) across {len(MODELS)} model(s)..."
|
| 57 |
|
| 58 |
+
# Process each prompt independently
|
| 59 |
+
for prompt_idx, prompt_text in enumerate(prompts, 1):
|
| 60 |
+
# Each prompt gets fresh responses from all models
|
| 61 |
+
for model in MODELS:
|
| 62 |
+
response = query_model(model, prompt_text, max_tokens, temperature)
|
| 63 |
+
|
| 64 |
+
results.append({
|
| 65 |
+
'timestamp': datetime.now().isoformat(),
|
| 66 |
+
'prompt_number': prompt_idx,
|
| 67 |
+
'prompt': prompt_text,
|
| 68 |
+
'model': model.split('/')[-1], # Short model name
|
| 69 |
+
'full_model': model,
|
| 70 |
+
'response': response
|
| 71 |
+
})
|
| 72 |
|
| 73 |
df = pd.DataFrame(results)
|
| 74 |
+
csv_filename = f"batch_responses_{datetime.now().strftime('%Y%m%d_%H%M%S')}.csv"
|
| 75 |
df.to_csv(csv_filename, index=False)
|
| 76 |
|
| 77 |
+
completion_msg = f"β
Completed! Processed {len(prompts)} prompt(s) Γ {len(MODELS)} models = {len(results)} total responses"
|
| 78 |
+
|
| 79 |
+
return df, csv_filename, completion_msg
|
| 80 |
|
| 81 |
# Gradio interface
|
| 82 |
+
with gr.Blocks(title="Batch LLM Response Collector") as demo:
|
| 83 |
gr.Markdown("""
|
| 84 |
+
# π€ Batch Multi-LLM Response Collector
|
| 85 |
|
| 86 |
Compare responses from 4 different LLMs (2 US, 2 China):
|
| 87 |
- **Llama 3.3 70B** πΊπΈ - Meta's latest model (USA)
|
|
|
|
| 89 |
- **Qwen 2.5 72B** π¨π³ - Alibaba's flagship model (China)
|
| 90 |
- **DeepSeek R1** π¨π³ - DeepSeek's reasoning model (China)
|
| 91 |
|
| 92 |
+
**Batch Processing:** Enter multiple prompts (one per line). Each prompt is processed independently with no conversation history or cross-contamination.
|
| 93 |
""")
|
| 94 |
|
| 95 |
with gr.Row():
|
| 96 |
with gr.Column():
|
| 97 |
prompt_input = gr.Textbox(
|
| 98 |
+
label="Enter your prompts (one per line)",
|
| 99 |
+
placeholder="What is artificial intelligence?\nExplain quantum computing.\nDescribe machine learning.",
|
| 100 |
+
lines=8
|
| 101 |
)
|
| 102 |
|
| 103 |
with gr.Row():
|
|
|
|
| 116 |
label="Temperature"
|
| 117 |
)
|
| 118 |
|
| 119 |
+
submit_btn = gr.Button("Process Batch", variant="primary", size="lg")
|
| 120 |
|
| 121 |
+
status_output = gr.Textbox(label="Status", interactive=False)
|
| 122 |
df_output = gr.Dataframe(label="Results", wrap=True)
|
| 123 |
csv_output = gr.File(label="Download CSV")
|
| 124 |
|
| 125 |
submit_btn.click(
|
| 126 |
+
fn=collect_batch_responses,
|
| 127 |
inputs=[prompt_input, max_tokens, temperature],
|
| 128 |
+
outputs=[df_output, csv_output, status_output]
|
| 129 |
)
|
| 130 |
|
| 131 |
gr.Markdown("""
|
| 132 |
---
|
| 133 |
### π About
|
| 134 |
- Uses Hugging Face Router API
|
| 135 |
+
- **Each prompt is completely independent** - no conversation history
|
| 136 |
+
- Multiple prompts processed sequentially (one per line)
|
| 137 |
+
- Each prompt gets fresh responses from all 4 models
|
| 138 |
+
- Results include prompt_number for easy tracking
|
| 139 |
+
- All results saved to timestamped CSV for analysis
|
| 140 |
+
|
| 141 |
+
### π‘ Tips
|
| 142 |
+
- Separate prompts with line breaks
|
| 143 |
+
- Empty lines are automatically ignored
|
| 144 |
+
- Processing time scales with: (number of prompts) Γ (number of models)
|
| 145 |
""")
|
| 146 |
|
| 147 |
if __name__ == "__main__":
|