drshabbirhassan commited on
Commit
f38d603
·
verified ·
1 Parent(s): ffa08c7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +33 -23
app.py CHANGED
@@ -3,7 +3,7 @@ import os
3
  import requests
4
 
5
  GROK_KEY = os.getenv("GROK_KEY")
6
- GROK_URL = "https://api.grokapi.com/v1/generate" # Example URL, use actual Grok endpoint
7
 
8
  def call_grok(prompt, max_tokens=300):
9
  headers = {"Authorization": f"Bearer {GROK_KEY}"}
@@ -22,7 +22,8 @@ def css_lexiscan_final(text_input):
22
  if not text_input.strip():
23
  return "⚠️ Please enter some text.", "⚠️ Please enter some text."
24
 
25
- # PASI prompt
 
26
  precis_prompt = f"""
27
  Summarize the text below following PASI rules (CSS exam):
28
  - One-third length
@@ -30,65 +31,74 @@ Summarize the text below following PASI rules (CSS exam):
30
  - Third-person pronouns
31
  - No personal opinions/examples
32
  - Condensed meaning
33
-
34
  Output format:
35
  <<<TITLE>>>
36
  <Title here>
37
  <<<PRECIS>>>
38
  <Precis here>
39
-
40
  Text:
41
  {text_input}
42
  """
 
43
  precis_raw = call_grok(precis_prompt, max_tokens=300)
44
- # Extract title + precis
45
- import re
46
- title_match = re.search(r'<<<TITLE>>>\s*(.*?)\s*<<<PRECIS>>>', precis_raw, re.DOTALL)
47
  precis_match = re.search(r'<<<PRECIS>>>\s*(.*)', precis_raw, re.DOTALL)
 
48
  title_text = title_match.group(1).strip() if title_match else ""
49
  precis_text = precis_match.group(1).strip() if precis_match else ""
 
50
  final_precis = f"{title_text}\n{precis_text}"
51
 
52
- # Vocabulary prompt
53
  vocab_prompt = f"""
54
  Extract 5-7 difficult or uncommon words from the following text and give their meanings in simple English.
55
  Use numbered list format:
56
-
57
  1. example_word: meaning
58
  2. another_word: meaning
59
  3. yet_another_word: meaning
60
-
61
- Only include words actually present in the text. Output ONLY the list of words and meanings.
62
-
63
  Text:
64
  {text_input}
65
  """
 
66
  vocab_raw = call_grok(vocab_prompt, max_tokens=250)
67
  vocab_clean = vocab_raw.replace(text_input, "").strip()
68
 
69
  return final_precis, vocab_clean
70
 
71
- # Gradio UI
72
- with gr.Blocks(css="""
 
 
73
  body {background-color: #1E1E2F; color: #FFFFFF; font-family: 'Poppins', sans-serif;}
74
  .gradio-container {border-radius: 20px; padding: 20px;}
75
- .gr-button {background-color: #FF6B6B; color: white; font-weight: bold;}
76
- .gr-textbox textarea {font-size: 18px; min-height: 180px;}
77
- .gr-textbox label {font-size: 20px; font-weight: bold;}
78
  h1 {color: #FFD93D;}
79
  h2 {color: #6BCB77;}
80
- """) as demo:
 
 
 
 
 
81
  gr.Markdown("<h1>✨ CSS LexiScan MVP ✨</h1>")
82
  gr.Markdown("<h2>Enter text & get PASI-style precis + vocabulary</h2>")
83
-
84
  with gr.Row():
85
  with gr.Column():
86
- text_input = gr.Textbox(label="Enter Editorial / Paragraph", placeholder="Paste your text here...", lines=8)
 
 
87
  submit_btn = gr.Button("Analyze Text")
 
88
  with gr.Column():
89
  precis_output = gr.Textbox(label="📜 Precis Output", lines=10)
90
  vocab_output = gr.Textbox(label="📝 Difficult Words + Meanings", lines=10)
91
-
92
- submit_btn.click(css_lexiscan_final, inputs=text_input, outputs=[precis_output, vocab_output])
93
 
94
- demo.launch()
 
 
 
 
 
3
  import requests
4
 
5
  GROK_KEY = os.getenv("GROK_KEY")
6
+ GROK_URL = "https://api.grokapi.com/v1/generate"
7
 
8
  def call_grok(prompt, max_tokens=300):
9
  headers = {"Authorization": f"Bearer {GROK_KEY}"}
 
22
  if not text_input.strip():
23
  return "⚠️ Please enter some text.", "⚠️ Please enter some text."
24
 
25
+ import re
26
+
27
  precis_prompt = f"""
28
  Summarize the text below following PASI rules (CSS exam):
29
  - One-third length
 
31
  - Third-person pronouns
32
  - No personal opinions/examples
33
  - Condensed meaning
 
34
  Output format:
35
  <<<TITLE>>>
36
  <Title here>
37
  <<<PRECIS>>>
38
  <Precis here>
 
39
  Text:
40
  {text_input}
41
  """
42
+
43
  precis_raw = call_grok(precis_prompt, max_tokens=300)
44
+
45
+ title_match = re.search(r'<<<TITLE>>>\s*(.?)\s<<<PRECIS>>>', precis_raw, re.DOTALL)
 
46
  precis_match = re.search(r'<<<PRECIS>>>\s*(.*)', precis_raw, re.DOTALL)
47
+
48
  title_text = title_match.group(1).strip() if title_match else ""
49
  precis_text = precis_match.group(1).strip() if precis_match else ""
50
+
51
  final_precis = f"{title_text}\n{precis_text}"
52
 
 
53
  vocab_prompt = f"""
54
  Extract 5-7 difficult or uncommon words from the following text and give their meanings in simple English.
55
  Use numbered list format:
 
56
  1. example_word: meaning
57
  2. another_word: meaning
58
  3. yet_another_word: meaning
59
+ Only include words actually present in the text. Output ONLY the list.
 
 
60
  Text:
61
  {text_input}
62
  """
63
+
64
  vocab_raw = call_grok(vocab_prompt, max_tokens=250)
65
  vocab_clean = vocab_raw.replace(text_input, "").strip()
66
 
67
  return final_precis, vocab_clean
68
 
69
+
70
+ # ----------------------------- GRADIO UI -----------------------------
71
+ custom_css = """
72
+ <style>
73
  body {background-color: #1E1E2F; color: #FFFFFF; font-family: 'Poppins', sans-serif;}
74
  .gradio-container {border-radius: 20px; padding: 20px;}
75
+ .gr-button {background-color: #FF6B6B !important; color: white !important; font-weight: bold;}
76
+ textarea {font-size: 18px !important; min-height: 180px !important;}
77
+ label {font-size: 20px !important; font-weight: bold !important;}
78
  h1 {color: #FFD93D;}
79
  h2 {color: #6BCB77;}
80
+ </style>
81
+ """
82
+
83
+ with gr.Blocks() as demo:
84
+ gr.HTML(custom_css)
85
+
86
  gr.Markdown("<h1>✨ CSS LexiScan MVP ✨</h1>")
87
  gr.Markdown("<h2>Enter text & get PASI-style precis + vocabulary</h2>")
88
+
89
  with gr.Row():
90
  with gr.Column():
91
+ text_input = gr.Textbox(label="Enter Editorial / Paragraph",
92
+ placeholder="Paste your text here...",
93
+ lines=8)
94
  submit_btn = gr.Button("Analyze Text")
95
+
96
  with gr.Column():
97
  precis_output = gr.Textbox(label="📜 Precis Output", lines=10)
98
  vocab_output = gr.Textbox(label="📝 Difficult Words + Meanings", lines=10)
 
 
99
 
100
+ submit_btn.click(css_lexiscan_final,
101
+ inputs=text_input,
102
+ outputs=[precis_output, vocab_output])
103
+
104
+ demo.launch()