File size: 3,252 Bytes
bb562ca
3a48954
 
e96d361
bb562ca
f38d603
3a48954
 
 
 
 
 
 
 
 
 
 
 
 
e96d361
 
 
 
 
f38d603
 
e96d361
3a48954
 
 
 
 
 
e96d361
 
 
 
 
 
 
 
f38d603
3a48954
f38d603
 
e96d361
f38d603
e96d361
 
f38d603
e96d361
 
 
 
3a48954
 
 
 
f38d603
e96d361
 
 
f38d603
3a48954
e96d361
 
 
 
f38d603
 
 
 
e96d361
 
f38d603
 
 
e96d361
 
f38d603
 
 
 
 
 
e96d361
 
f38d603
e96d361
 
f38d603
 
 
e96d361
f38d603
e96d361
 
 
 
f38d603
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
mport gradio as gr
import os
import requests

GROK_KEY = os.getenv("GROK_KEY")
GROK_URL = "https://api.grokapi.com/v1/generate"

def call_grok(prompt, max_tokens=300):
    headers = {"Authorization": f"Bearer {GROK_KEY}"}
    payload = {
        "prompt": prompt,
        "max_tokens": max_tokens,
        "temperature": 0.2
    }
    response = requests.post(GROK_URL, headers=headers, json=payload)
    if response.status_code == 200:
        return response.json()["text"]
    else:
        return f"Error: {response.status_code} - {response.text}"

def css_lexiscan_final(text_input):
    if not text_input.strip():
        return "⚠️ Please enter some text.", "⚠️ Please enter some text."

    import re

    precis_prompt = f"""
Summarize the text below following PASI rules (CSS exam):
- One-third length
- Suitable title
- Third-person pronouns
- No personal opinions/examples
- Condensed meaning
Output format:
<<<TITLE>>>
<Title here>
<<<PRECIS>>>
<Precis here>
Text:
{text_input}
"""

    precis_raw = call_grok(precis_prompt, max_tokens=300)

    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:
1. example_word: meaning
2. another_word: meaning
3. yet_another_word: meaning
Only include words actually present in the text. Output ONLY the list.
Text:
{text_input}
"""

    vocab_raw = call_grok(vocab_prompt, max_tokens=250)
    vocab_clean = vocab_raw.replace(text_input, "").strip()

    return final_precis, vocab_clean


# ----------------------------- GRADIO UI -----------------------------
custom_css = """
<style>
body {background-color: #1E1E2F; color: #FFFFFF; font-family: 'Poppins', sans-serif;}
.gradio-container {border-radius: 20px; padding: 20px;}
.gr-button {background-color: #FF6B6B !important; color: white !important; font-weight: bold;}
textarea {font-size: 18px !important; min-height: 180px !important;}
label {font-size: 20px !important; font-weight: bold !important;}
h1 {color: #FFD93D;}
h2 {color: #6BCB77;}
</style>
"""

with gr.Blocks() as demo:
    gr.HTML(custom_css)

    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()