Update app.py
Browse files
app.py
CHANGED
|
@@ -1,4 +1,5 @@
|
|
| 1 |
# app.py — CSS LexiScan for Hugging Face Spaces
|
|
|
|
| 2 |
# Fully self-contained: précis + vocabulary extraction + Gradio UI
|
| 3 |
|
| 4 |
import os
|
|
@@ -38,7 +39,7 @@ FEW_SHOT = (
|
|
| 38 |
)
|
| 39 |
|
| 40 |
# === Helper Functions ===
|
| 41 |
-
def get_groq_api_key(secret_name: str = "
|
| 42 |
key = os.environ.get(secret_name)
|
| 43 |
if not key:
|
| 44 |
raise ValueError(f"No Groq API key found. Set it in HF Secrets as '{secret_name}'.")
|
|
@@ -111,13 +112,16 @@ def build_app(client: Groq):
|
|
| 111 |
passage_input = gr.Textbox(lines=10, label="Paste your passage here:")
|
| 112 |
generate_btn = gr.Button("Generate Précis & Vocabulary")
|
| 113 |
precis_output = gr.Textbox(lines=5, label="Generated Précis")
|
| 114 |
-
vocab_output = gr.Dataframe(
|
|
|
|
|
|
|
|
|
|
| 115 |
generate_btn.click(fn=process_text, inputs=passage_input, outputs=[precis_output, vocab_output])
|
| 116 |
return demo
|
| 117 |
|
| 118 |
# === Main ===
|
| 119 |
if __name__ == "__main__":
|
| 120 |
-
api_key = get_groq_api_key()
|
| 121 |
client = make_groq_client(api_key)
|
| 122 |
app = build_app(client)
|
| 123 |
app.launch() # HF Spaces will automatically host this
|
|
|
|
| 1 |
# app.py — CSS LexiScan for Hugging Face Spaces
|
| 2 |
+
# Uses HF Secret 'SCAN' for Groq API key
|
| 3 |
# Fully self-contained: précis + vocabulary extraction + Gradio UI
|
| 4 |
|
| 5 |
import os
|
|
|
|
| 39 |
)
|
| 40 |
|
| 41 |
# === Helper Functions ===
|
| 42 |
+
def get_groq_api_key(secret_name: str = "SCAN") -> str:
|
| 43 |
key = os.environ.get(secret_name)
|
| 44 |
if not key:
|
| 45 |
raise ValueError(f"No Groq API key found. Set it in HF Secrets as '{secret_name}'.")
|
|
|
|
| 112 |
passage_input = gr.Textbox(lines=10, label="Paste your passage here:")
|
| 113 |
generate_btn = gr.Button("Generate Précis & Vocabulary")
|
| 114 |
precis_output = gr.Textbox(lines=5, label="Generated Précis")
|
| 115 |
+
vocab_output = gr.Dataframe(
|
| 116 |
+
headers=["word", "part_of_speech", "meaning", "example"],
|
| 117 |
+
label="Difficult Words"
|
| 118 |
+
)
|
| 119 |
generate_btn.click(fn=process_text, inputs=passage_input, outputs=[precis_output, vocab_output])
|
| 120 |
return demo
|
| 121 |
|
| 122 |
# === Main ===
|
| 123 |
if __name__ == "__main__":
|
| 124 |
+
api_key = get_groq_api_key("SCAN") # <-- Uses HF secret named 'SCAN'
|
| 125 |
client = make_groq_client(api_key)
|
| 126 |
app = build_app(client)
|
| 127 |
app.launch() # HF Spaces will automatically host this
|