Spaces:
Sleeping
Sleeping
Update
Browse files- README.md +1 -1
- config.py +20 -20
- main.py +30 -37
- question_runner.py +0 -1
- requirements.txt +5 -5
README.md
CHANGED
|
@@ -4,7 +4,7 @@ emoji: 🏛️
|
|
| 4 |
colorFrom: indigo
|
| 5 |
colorTo: blue
|
| 6 |
sdk: gradio
|
| 7 |
-
sdk_version: 5.
|
| 8 |
app_file: main.py
|
| 9 |
pinned: false
|
| 10 |
---
|
|
|
|
| 4 |
colorFrom: indigo
|
| 5 |
colorTo: blue
|
| 6 |
sdk: gradio
|
| 7 |
+
sdk_version: 5.49.1
|
| 8 |
app_file: main.py
|
| 9 |
pinned: false
|
| 10 |
---
|
config.py
CHANGED
|
@@ -1,20 +1,20 @@
|
|
| 1 |
-
# config.py
|
| 2 |
-
|
| 3 |
-
# === API SETTINGS ===
|
| 4 |
-
OPENROUTER_API_KEY = "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"
|
| 5 |
-
OPENROUTER_API_URL = "https://openrouter.ai/api/v1/chat/completions"
|
| 6 |
-
|
| 7 |
-
# === GOOGLE DOCS INPUT ===
|
| 8 |
-
SYNTAX_DOC_URL = "https://docs.google.com/document/d/1gxQbsAIek9CMDPalQOGlCq-fmi-WRrS69_yEx6b206U/export?format=txt"
|
| 9 |
-
MORPHOLOGY_DOC_URL = "https://docs.google.com/document/d/1hIal62lGso9BqfqKfB0ws8g8pBZsX-LBSTrge3M6pBM/export?format=txt"
|
| 10 |
-
|
| 11 |
-
# === MODEL PRIORITY ===
|
| 12 |
-
# Ordered from best to weakest. Will try top → bottom until one succeeds.
|
| 13 |
-
MODEL_PRIORITY = [
|
| 14 |
-
"anthropic/claude-3-haiku",
|
| 15 |
-
"openai/gpt-3.5-turbo",
|
| 16 |
-
"nousresearch/nous-hermes-2-mistral",
|
| 17 |
-
"meta-llama/llama-3-8b-instruct",
|
| 18 |
-
"mistralai/mistral-7b-instruct",
|
| 19 |
-
"gryphe/mythomax-l2-13b"
|
| 20 |
-
]
|
|
|
|
| 1 |
+
# config.py
|
| 2 |
+
|
| 3 |
+
# === API SETTINGS ===
|
| 4 |
+
OPENROUTER_API_KEY = "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"
|
| 5 |
+
OPENROUTER_API_URL = "https://openrouter.ai/api/v1/chat/completions"
|
| 6 |
+
|
| 7 |
+
# === GOOGLE DOCS INPUT ===
|
| 8 |
+
SYNTAX_DOC_URL = "https://docs.google.com/document/d/1gxQbsAIek9CMDPalQOGlCq-fmi-WRrS69_yEx6b206U/export?format=txt"
|
| 9 |
+
MORPHOLOGY_DOC_URL = "https://docs.google.com/document/d/1hIal62lGso9BqfqKfB0ws8g8pBZsX-LBSTrge3M6pBM/export?format=txt"
|
| 10 |
+
|
| 11 |
+
# === MODEL PRIORITY ===
|
| 12 |
+
# Ordered from best to weakest. Will try top → bottom until one succeeds.
|
| 13 |
+
MODEL_PRIORITY = [
|
| 14 |
+
"anthropic/claude-3-haiku",
|
| 15 |
+
"openai/gpt-3.5-turbo",
|
| 16 |
+
"nousresearch/nous-hermes-2-mistral",
|
| 17 |
+
"meta-llama/llama-3-8b-instruct",
|
| 18 |
+
"mistralai/mistral-7b-instruct",
|
| 19 |
+
"gryphe/mythomax-l2-13b"
|
| 20 |
+
]
|
main.py
CHANGED
|
@@ -6,11 +6,6 @@ from question_runner import run_tool
|
|
| 6 |
from config import MODEL_PRIORITY, SYNTAX_DOC_URL, MORPHOLOGY_DOC_URL
|
| 7 |
from doc_utils import get_questions_from_doc
|
| 8 |
|
| 9 |
-
# --- ZERO-GPU ENTRYPOINT (must be top-level and referenced by Gradio) ---
|
| 10 |
-
def run_query(passage: str, doc_type: str):
|
| 11 |
-
# Delegate to your existing business logic
|
| 12 |
-
return run_tool(passage, doc_type)
|
| 13 |
-
|
| 14 |
# Estimate runtime based on # of questions
|
| 15 |
def estimate_runtime(passage, doc_type):
|
| 16 |
if not passage or not doc_type:
|
|
@@ -22,46 +17,44 @@ def estimate_runtime(passage, doc_type):
|
|
| 22 |
est_seconds = round(len(questions) * 2.5, 1)
|
| 23 |
return f"Estimated generation time: ~{est_seconds} seconds"
|
| 24 |
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
**Currently prioritized model:** `{top_model}`
|
| 41 |
**Model fallback chain (if needed):**
|
| 42 |
{full_model_list}
|
| 43 |
""")
|
| 44 |
|
| 45 |
-
|
| 46 |
-
output_text = gr.Textbox(label="Generated Answers", lines=25, interactive=False)
|
| 47 |
-
output_file = gr.File(label="Download Answers (.txt)", interactive=False)
|
| 48 |
|
| 49 |
-
|
|
|
|
|
|
|
| 50 |
|
| 51 |
-
|
| 52 |
-
|
| 53 |
|
| 54 |
-
|
| 55 |
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
|
| 64 |
if __name__ == "__main__":
|
| 65 |
-
|
| 66 |
-
app = build_app()
|
| 67 |
-
app.launch()
|
|
|
|
| 6 |
from config import MODEL_PRIORITY, SYNTAX_DOC_URL, MORPHOLOGY_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:
|
|
|
|
| 17 |
est_seconds = round(len(questions) * 2.5, 1)
|
| 18 |
return f"Estimated generation time: ~{est_seconds} seconds"
|
| 19 |
|
| 20 |
+
# Build the Gradio interface at module level (required for HF Spaces)
|
| 21 |
+
with gr.Blocks(theme=Soft()) as demo:
|
| 22 |
+
gr.Markdown("""
|
| 23 |
+
## **Classical Language Query Assistant**
|
| 24 |
+
Submit a Latin or Greek passage and select the question type.
|
| 25 |
+
Answers are generated using a rotating chain of hosted AI models via OpenRouter.
|
| 26 |
+
""")
|
| 27 |
+
|
| 28 |
+
with gr.Row():
|
| 29 |
+
passage_input = gr.Textbox(label="Latin or Greek Passage", lines=4)
|
| 30 |
+
question_type = gr.Radio(["Syntax", "Morphology"], label="Question Type")
|
| 31 |
+
|
| 32 |
+
top_model = MODEL_PRIORITY[0]
|
| 33 |
+
full_model_list = "\n".join(f"- `{m}`" for m in MODEL_PRIORITY)
|
| 34 |
+
gr.Markdown(f"""
|
| 35 |
**Currently prioritized model:** `{top_model}`
|
| 36 |
**Model fallback chain (if needed):**
|
| 37 |
{full_model_list}
|
| 38 |
""")
|
| 39 |
|
| 40 |
+
estimated_time_box = gr.Textbox(label="Estimated Time", interactive=False)
|
|
|
|
|
|
|
| 41 |
|
| 42 |
+
with gr.Row():
|
| 43 |
+
output_text = gr.Textbox(label="Generated Answers", lines=25, interactive=False)
|
| 44 |
+
output_file = gr.File(label="Download Answers (.txt)", interactive=False)
|
| 45 |
|
| 46 |
+
passage_input.change(fn=estimate_runtime, inputs=[passage_input, question_type], outputs=estimated_time_box)
|
| 47 |
+
question_type.change(fn=estimate_runtime, inputs=[passage_input, question_type], outputs=estimated_time_box)
|
| 48 |
|
| 49 |
+
submit_button = gr.Button("Generate Answers")
|
| 50 |
|
| 51 |
+
# Connect the button to run_tool function directly
|
| 52 |
+
submit_button.click(
|
| 53 |
+
fn=run_tool,
|
| 54 |
+
inputs=[passage_input, question_type],
|
| 55 |
+
outputs=[output_text, output_file, estimated_time_box],
|
| 56 |
+
api_name="generate"
|
| 57 |
+
)
|
| 58 |
|
| 59 |
if __name__ == "__main__":
|
| 60 |
+
demo.launch()
|
|
|
|
|
|
question_runner.py
CHANGED
|
@@ -5,7 +5,6 @@ from router_client import query_model
|
|
| 5 |
from doc_utils import get_questions_from_doc
|
| 6 |
from config import SYNTAX_DOC_URL, MORPHOLOGY_DOC_URL
|
| 7 |
|
| 8 |
-
# No GPU needed - we're just making API calls
|
| 9 |
def run_tool(passage, doc_type):
|
| 10 |
if not passage.strip():
|
| 11 |
return "Please enter a passage to analyze.", None, None
|
|
|
|
| 5 |
from doc_utils import get_questions_from_doc
|
| 6 |
from config import SYNTAX_DOC_URL, MORPHOLOGY_DOC_URL
|
| 7 |
|
|
|
|
| 8 |
def run_tool(passage, doc_type):
|
| 9 |
if not passage.strip():
|
| 10 |
return "Please enter a passage to analyze.", None, None
|
requirements.txt
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
-
gradio==5.49.1
|
| 2 |
-
requests>=2.31.0
|
| 3 |
-
spaces
|
| 4 |
-
huggingface_hub>=0.20.0
|
| 5 |
-
--extra-index-url https://download.pytorch.org/whl/cu113
|
| 6 |
torch
|
|
|
|
| 1 |
+
gradio==5.49.1
|
| 2 |
+
requests>=2.31.0
|
| 3 |
+
spaces
|
| 4 |
+
huggingface_hub>=0.20.0
|
| 5 |
+
--extra-index-url https://download.pytorch.org/whl/cu113
|
| 6 |
torch
|