Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,8 +3,8 @@ import gradio as gr
|
|
| 3 |
import google.generativeai as genai
|
| 4 |
import requests
|
| 5 |
import json
|
| 6 |
-
import time
|
| 7 |
import os
|
|
|
|
| 8 |
|
| 9 |
genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))
|
| 10 |
gemini_model = genai.GenerativeModel("gemini-2.0-flash")
|
|
@@ -78,30 +78,22 @@ Question: {question}
|
|
| 78 |
distractors = [line.split(":", 1)[1].strip() for line in lines if line.startswith("Distractor")]
|
| 79 |
|
| 80 |
if len(distractors) != 3:
|
| 81 |
-
return "
|
| 82 |
|
| 83 |
-
claude_llm = OpenRouter("anthropic/claude-3.5-sonnet-20240612", "
|
| 84 |
claude_prompt = prepare_claude_ranking_prompt(question, correct, distractors)
|
| 85 |
ranking = call_openrouter(claude_llm, claude_prompt)
|
| 86 |
|
| 87 |
-
|
| 88 |
-
output += f"**Correct Answer:** {correct}\n"
|
| 89 |
-
for i, d in enumerate(distractors, 1):
|
| 90 |
-
output += f"**Distractor {i}:** {d}\n"
|
| 91 |
-
output += f"\n**Claude Ranking:** {ranking.strip()}"
|
| 92 |
-
|
| 93 |
-
return output, gemini_response, claude_prompt
|
| 94 |
-
|
| 95 |
|
| 96 |
iface = gr.Interface(
|
| 97 |
fn=generate_and_rank,
|
| 98 |
inputs=gr.Textbox(label="Enter your MCQ Question"),
|
| 99 |
outputs=[
|
| 100 |
-
gr.Textbox(label="
|
| 101 |
-
gr.Textbox(label="
|
| 102 |
-
gr.Textbox(label="Claude Prompt")
|
| 103 |
],
|
| 104 |
title="Confusing Distractor Generator + Claude Ranking"
|
| 105 |
)
|
| 106 |
|
| 107 |
-
iface.launch()
|
|
|
|
| 3 |
import google.generativeai as genai
|
| 4 |
import requests
|
| 5 |
import json
|
|
|
|
| 6 |
import os
|
| 7 |
+
import time
|
| 8 |
|
| 9 |
genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))
|
| 10 |
gemini_model = genai.GenerativeModel("gemini-2.0-flash")
|
|
|
|
| 78 |
distractors = [line.split(":", 1)[1].strip() for line in lines if line.startswith("Distractor")]
|
| 79 |
|
| 80 |
if len(distractors) != 3:
|
| 81 |
+
return gemini_response, "ERROR (Invalid distractor count)"
|
| 82 |
|
| 83 |
+
claude_llm = OpenRouter("anthropic/claude-3.5-sonnet-20240612", os.getenv("OPENROUTER_API_KEY"))
|
| 84 |
claude_prompt = prepare_claude_ranking_prompt(question, correct, distractors)
|
| 85 |
ranking = call_openrouter(claude_llm, claude_prompt)
|
| 86 |
|
| 87 |
+
return gemini_response, ranking.strip()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 88 |
|
| 89 |
iface = gr.Interface(
|
| 90 |
fn=generate_and_rank,
|
| 91 |
inputs=gr.Textbox(label="Enter your MCQ Question"),
|
| 92 |
outputs=[
|
| 93 |
+
gr.Textbox(label="Generated Answer and Distractors (Gemini)"),
|
| 94 |
+
gr.Textbox(label="Claude's Ranking")
|
|
|
|
| 95 |
],
|
| 96 |
title="Confusing Distractor Generator + Claude Ranking"
|
| 97 |
)
|
| 98 |
|
| 99 |
+
iface.launch()
|