Spaces:
Sleeping
Sleeping
Delete main.py
Browse files
main.py
DELETED
|
@@ -1,65 +0,0 @@
|
|
| 1 |
-
# main.py
|
| 2 |
-
import gradio as gr
|
| 3 |
-
from gradio.themes import Soft
|
| 4 |
-
|
| 5 |
-
from question_runner import run_tool
|
| 6 |
-
from config import MODEL_PRIORITY, SYNTAX_DOC_URL, MORPHOLOGY_DOC_URL, SEMANTICS_DOC_URL
|
| 7 |
-
from doc_utils import get_questions_from_doc
|
| 8 |
-
|
| 9 |
-
# Estimate runtime based on # of questions
|
| 10 |
-
def estimate_runtime(passage, doc_type):
|
| 11 |
-
if not passage or not doc_type:
|
| 12 |
-
return ""
|
| 13 |
-
if doc_type.lower() == "syntax":
|
| 14 |
-
doc_url = SYNTAX_DOC_URL
|
| 15 |
-
elif doc_type.lower() == "morphology":
|
| 16 |
-
doc_url = MORPHOLOGY_DOC_URL
|
| 17 |
-
else: # semantics
|
| 18 |
-
doc_url = SEMANTICS_DOC_URL
|
| 19 |
-
questions = get_questions_from_doc(doc_url)
|
| 20 |
-
if not questions or (isinstance(questions, list) and questions and str(questions[0]).startswith("Error")):
|
| 21 |
-
return "Unable to load questions."
|
| 22 |
-
est_seconds = round(len(questions) * 2.5, 1)
|
| 23 |
-
return f"Estimated generation time: ~{est_seconds} seconds"
|
| 24 |
-
|
| 25 |
-
# Build the Gradio interface at module level (required for HF Spaces)
|
| 26 |
-
with gr.Blocks(theme=Soft()) as demo:
|
| 27 |
-
gr.Markdown("""
|
| 28 |
-
## **Classical Language Query Assistant**
|
| 29 |
-
Submit a Latin or Greek passage and select the question type.
|
| 30 |
-
Answers are generated using a rotating chain of hosted AI models via OpenRouter.
|
| 31 |
-
""")
|
| 32 |
-
|
| 33 |
-
with gr.Row():
|
| 34 |
-
passage_input = gr.Textbox(label="Latin or Greek Passage", lines=4)
|
| 35 |
-
question_type = gr.Radio(["Syntax", "Morphology", "Semantics"], label="Question Type")
|
| 36 |
-
|
| 37 |
-
top_model = MODEL_PRIORITY[0]
|
| 38 |
-
full_model_list = "\n".join(f"- `{m}`" for m in MODEL_PRIORITY)
|
| 39 |
-
gr.Markdown(f"""
|
| 40 |
-
**Currently prioritized model:** `{top_model}`
|
| 41 |
-
**Model fallback chain (if needed):**
|
| 42 |
-
{full_model_list}
|
| 43 |
-
""")
|
| 44 |
-
|
| 45 |
-
estimated_time_box = gr.Textbox(label="Estimated Time", interactive=False)
|
| 46 |
-
|
| 47 |
-
with gr.Row():
|
| 48 |
-
output_text = gr.Textbox(label="Generated Answers", lines=25, interactive=False)
|
| 49 |
-
output_file = gr.File(label="Download Answers (.txt)", interactive=False)
|
| 50 |
-
|
| 51 |
-
passage_input.change(fn=estimate_runtime, inputs=[passage_input, question_type], outputs=estimated_time_box)
|
| 52 |
-
question_type.change(fn=estimate_runtime, inputs=[passage_input, question_type], outputs=estimated_time_box)
|
| 53 |
-
|
| 54 |
-
submit_button = gr.Button("Generate Answers")
|
| 55 |
-
|
| 56 |
-
# Connect the button to run_tool function directly
|
| 57 |
-
submit_button.click(
|
| 58 |
-
fn=run_tool,
|
| 59 |
-
inputs=[passage_input, question_type],
|
| 60 |
-
outputs=[output_text, output_file, estimated_time_box],
|
| 61 |
-
api_name="generate"
|
| 62 |
-
)
|
| 63 |
-
|
| 64 |
-
if __name__ == "__main__":
|
| 65 |
-
demo.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|