Tayoke commited on
Commit
8fc51a2
·
verified ·
1 Parent(s): 2d88fac

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +178 -0
app.py ADDED
@@ -0,0 +1,178 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+
3
+
4
+
5
+ model_client = genai.Client(
6
+ api_key=API_KEY,
7
+ http_options=types.HttpOptions(
8
+ timeout=MODEL_TIMEOUT_MS,
9
+ retry_options=types.HttpRetryOptions(
10
+ attempts=1
11
+ )
12
+ )
13
+ )
14
+
15
+
16
+
17
+
18
+ # ============================================================
19
+ # WHOLE VIDEO CONTEXT PROMPT
20
+ # ============================================================
21
+
22
+
23
+ CONTEXT_PROMPT = r"""
24
+ Watch and understand the ENTIRE uploaded Chinese video.
25
+
26
+
27
+ This is NOT the final translation task.
28
+
29
+
30
+ Your job is to create a compact but detailed STORY / CHARACTER CONTEXT
31
+ that will later be given to another translation request.
32
+
33
+
34
+ Analyze the whole video from beginning to end.
35
+
36
+
37
+ Identify and record:
38
+
39
+
40
+ 1. Main characters
41
+ 2. Character names
42
+ 3. Gender
43
+ 4. Approximate age / age relationship
44
+ 5. Family relationships
45
+ 6. Husband / wife relationships
46
+ 7. Brother / sister relationships
47
+ 8. Parent / child relationships
48
+ 9. Boss / employee relationships
49
+ 10. Friends / enemies / business partners
50
+ 11. Important locations
51
+ 12. Important events in chronological order
52
+ 13. Important objects
53
+ 14. Important money amounts
54
+ 15. Important numbers
55
+ 16. Important dates / years / ages
56
+ 17. Important promises / threats / agreements
57
+ 18. Who is speaking to whom
58
+ 19. Any terminology that must remain consistent
59
+ 20. Any important story information that affects later dialogue
60
+
61
+
62
+ Pay special attention to:
63
+
64
+
65
+ - Chinese character names
66
+ - gender
67
+ - family relationships
68
+ - business relationships
69
+ - money
70
+ - numbers
71
+ - dates
72
+ - ages
73
+ - titles
74
+ - who is the boss
75
+ - who is the employee
76
+ - who is the partner
77
+ - who is the shareholder
78
+
79
+
80
+ Do NOT translate the entire dialogue.
81
+
82
+
83
+ Do NOT create SRT.
84
+
85
+
86
+ Do NOT write timestamps.
87
+
88
+
89
+ Return ONLY a concise structured context summary that can be supplied
90
+ to a later Chinese-to-Myanmar subtitle translation process.
91
+
92
+
93
+ Make the context useful for maintaining consistency across multiple
94
+ video chunks.
95
+ """
96
+
97
+
98
+
99
+
100
+ # ============================================================
101
+ # CHUNK TRANSLATION PROMPT
102
+ # ============================================================
103
+
104
+
105
+ def build_chunk_prompt(
106
+ context_summary,
107
+ primary_start,
108
+ primary_end
109
+ ):
110
+
111
+
112
+ return f"""
113
+ You are a professional Chinese-to-Myanmar subtitle translator.
114
+
115
+
116
+ The uploaded video is ONE CHUNK from a larger Chinese video.
117
+
118
+
119
+ You have also been given a context summary from the ENTIRE original video.
120
+
121
+
122
+ Use that context to maintain consistency of:
123
+
124
+
125
+ - character names
126
+ - gender
127
+ - age
128
+ - family relationships
129
+ - husband/wife
130
+ - brother/sister
131
+ - son/daughter
132
+ - parents
133
+ - boss/employee
134
+ - business partners
135
+ - shareholders
136
+ - money
137
+ - numbers
138
+ - dates
139
+ - terminology
140
+
141
+
142
+ ============================================================
143
+ WHOLE VIDEO CONTEXT
144
+ ============================================================
145
+
146
+
147
+ {context_summary}
148
+
149
+
150
+ ============================================================
151
+ CURRENT CHUNK
152
+ ============================================================
153
+
154
+
155
+ This chunk contains video around:
156
+
157
+
158
+ PRIMARY WINDOW:
159
+ {primary_start:.3f} seconds → {primary_end:.3f} seconds
160
+
161
+
162
+ The chunk may contain a few seconds of overlap around the primary window.
163
+
164
+
165
+ IMPORTANT:
166
+
167
+
168
+ Only create subtitles for spoken dialogue whose actual speech belongs
169
+ to the PRIMARY WINDOW.
170
+
171
+
172
+ Do NOT create duplicate subtitles for dialogue that belongs to the
173
+ previous or next chunk.
174
+
175
+
176
+ ============================================================
177
+
178
+ )