monicaa1212 commited on
Commit
7ef76c3
·
verified ·
1 Parent(s): a5d799f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +67 -21
app.py CHANGED
@@ -1,32 +1,78 @@
1
  import gradio as gr
2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
  def analyze(text):
4
- if not text.strip():
5
- return "Please paste some English text."
 
 
 
 
 
 
 
 
 
6
 
7
- return """
8
- 1. stumble upon
9
- 偶然发现
10
 
11
- 2. cut corners
12
- 偷工减料
 
 
13
 
14
- 3. on the fence
15
- 犹豫不决
16
  """
17
 
18
- demo = gr.Interface(
19
- fn=analyze,
20
- inputs=gr.Textbox(
21
- lines=12,
22
- label="Paste English Content"
23
- ),
24
- outputs=gr.Textbox(
 
 
 
 
 
 
 
25
  lines=12,
26
- label="Useful Expressions"
27
- ),
28
- title="InContext",
29
- description="Learn useful English expressions from real content."
30
- )
 
 
 
 
 
 
 
31
 
32
  demo.launch()
 
1
  import gradio as gr
2
 
3
+ demo_data = [
4
+ {
5
+ "expression": "stumble upon",
6
+ "meaning": "偶然发现",
7
+ "why": "比 find 更自然,更常见于真实英语表达。",
8
+ "example": "I stumbled upon a useful article while browsing online.",
9
+ "rewrite": "I accidentally found a useful article.\n→ I stumbled upon a useful article."
10
+ },
11
+ {
12
+ "expression": "cut corners",
13
+ "meaning": "偷工减料",
14
+ "why": "高频商务和日常表达。",
15
+ "example": "The company cut corners to save money.",
16
+ "rewrite": "The company tried to save money.\n→ The company cut corners."
17
+ },
18
+ {
19
+ "expression": "on the fence",
20
+ "meaning": "犹豫不决",
21
+ "why": "口语中非常常见。",
22
+ "example": "I'm still on the fence about changing jobs.",
23
+ "rewrite": "I haven't decided yet.\n→ I'm still on the fence."
24
+ }
25
+ ]
26
+
27
  def analyze(text):
28
+ cards = ""
29
+
30
+ for item in demo_data:
31
+ cards += f"""
32
+ ### {item['expression']}
33
+
34
+ **Meaning**
35
+ {item['meaning']}
36
+
37
+ **Why Learn It?**
38
+ {item['why']}
39
 
40
+ **Example**
41
+ {item['example']}
 
42
 
43
+ **Native Upgrade**
44
+ {item['rewrite']}
45
+
46
+ ---
47
 
 
 
48
  """
49
 
50
+ return cards
51
+
52
+
53
+ with gr.Blocks(title="InContext") as demo:
54
+
55
+ gr.Markdown(
56
+ """
57
+ # InContext
58
+
59
+ Learn reusable English expressions from real-world content.
60
+ """
61
+ )
62
+
63
+ text_input = gr.Textbox(
64
  lines=12,
65
+ placeholder="Paste English content here..."
66
+ )
67
+
68
+ analyze_btn = gr.Button("Analyze")
69
+
70
+ output = gr.Markdown()
71
+
72
+ analyze_btn.click(
73
+ fn=analyze,
74
+ inputs=text_input,
75
+ outputs=output
76
+ )
77
 
78
  demo.launch()