Spaces:
Runtime error
Runtime error
Create app.py
Browse files12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879import gradio as grimport refrom transformers import AutoModelForCausalLM, AutoTokenizer, pipeline
# Load LLM (Mistral 7B Instruct)model_name = "mistralai/Mistral-7B-Instruct-v0.1"tokenizer = AutoTokenizer.from_pretrained(model_name)model = AutoModelForCausalLM.from_pretrained(model_name)generator = pipeline("text-generation", model=model, tokenizer=tokenizer, max_new_tokens=300, temperature=0.2)
def css_lexiscan_final(text_input): if not text_input.strip(): return "⚠️ Please enter some text.", "⚠️ Please enter some text."
precis_prompt = f"""You are an expert CSS English tutor. Summarize the following text following PASI rules:- Precis must be about one-third of the original paragraph- Give a suitable title- Use third-person pronouns- No personal opinions or examples- Condense meaning faithfully
Output format:<<<TITLE>>><Title here><<<PRECIS>>><Precis here>
Text:{text_input}""" precis_raw = generator(precis_prompt, max_new_tokens=300, temperature=0.2)[0]['generated_text'] title_match = re.search(r'<<<TITLE>>>\s*(.*?)\s*<<<PRECIS>>>', precis_raw, re.DOTALL) precis_match = re.search(r'<<<PRECIS>>>\s*(.*)', precis_raw, re.DOTALL) title_text = title_match.group(1).strip() if title_match else "" precis_text = precis_match.group(1).strip() if precis_match else "" final_precis = f"{title_text}\n{precis_text}"
vocab_prompt = f"""Extract 5-7 difficult or uncommon words from the following text and give their meanings in simple English.Use numbered list format like this example:
1. example_word: the meaning of example_word in simple English2. another_word: simple meaning here3. yet_another_word: explanation in simple English
Only include words actually present in the text. Output ONLY the list of words and meanings.
Text:{text_input}""" vocab_raw = generator(vocab_prompt, max_new_tokens=250, temperature=0.2)[0]['generated_text'] vocab_clean = vocab_raw.replace(text_input, "").strip()
return final_precis, vocab_clean
with gr.Blocks(css="""body {background-color: #1E1E2F; color: #FFFFFF; font-family: 'Poppins', sans-serif;}.gradio-container {border-radius: 20px; padding: 20px;}.gr-button {background-color: #FF6B6B; color: white; font-weight: bold;}.gr-textbox textarea {font-size: 18px; min-height: 180px;}.gr-textbox label {font-size: 20px; font-weight: bold;}h1 {color: #FFD93D;}h2 {color: #6BCB77;}""") as demo: gr.Markdown("<h1>✨ CSS LexiScan MVP ✨</h1>") gr.Markdown("<h2>Enter text & get PASI-style precis + vocabulary</h2>") with gr.Row(): with gr.Column(): text_input = gr.Textbox(label="Enter Editorial / Paragraph", placeholder="Paste your text here...", lines=8) submit_btn = gr.Button("Analyze Text") with gr.Column(): precis_output = gr.Textbox(label="📜 Precis Output", lines=10) vocab_output = gr.Textbox(label="📝 Difficult Words + Meanings", lines=10) submit_btn.click(css_lexiscan_final, inputs=text_input, outputs=[precis_output, vocab_output])
demo.launch()app.pyAdded+79