Yashvj123 commited on
Commit
232c6f5
·
verified ·
1 Parent(s): 53e45e6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -48
app.py CHANGED
@@ -261,71 +261,46 @@ if uploaded_file:
261
 
262
 
263
 
264
- elif filtered_output and st.button("🌐 Translate to Hindi"):
265
- with st.spinner("Translating to Hindi..."):
266
-
267
- def clean_text(text):
268
- text = text.replace("•", "-") # Replace bullets
269
- text = re.sub(r"\s{2,}", " ", text) # Remove extra spaces
270
- text = re.sub(r"[^\w\s,.:-]", "", text) # Keep only safe characters
271
- return text
272
-
273
- cleaned_output = clean_text(filtered_output)
274
 
275
- try:
276
- hindi_text = GoogleTranslator(source='en', target='hi').translate(cleaned_output)
277
- except Exception as e:
278
- hindi_text = "[Translation failed]"
 
279
 
280
- # Formatting translated text
281
- formatted_text = re.sub(r'(?<=\s)-\s', r'\n- ', hindi_text)
282
 
283
- # Add line breaks before keywords
284
- keywords = ["खुराक और समय", "साइड इफेक्ट्स", "विशेष निर्देश"]
285
- for kw in keywords:
286
- formatted_text = formatted_text.replace(f"- {kw}", f"\n - {kw}")
287
 
288
- final_text = formatted_text.strip()
 
289
 
290
- st.markdown("#### 🌐 Hindi Translation")
291
- st.text_area("Translated Output (Hindi)", value=final_text, height=300)
 
 
292
 
293
- hindi_img_path = "hindi_output.png"
294
- save_text_as_image(final_text, hindi_img_path)
295
-
296
- st.markdown("#### 📥 Download (Hindi)")
297
- col3, col4 = st.columns(2)
298
- with col3:
299
- st.download_button("⬇️ Hindi TXT", data=final_text.encode(), file_name="hindi_medicine_analysis.txt")
300
- with col4:
301
- with open(hindi_img_path, "rb") as img_file:
302
- st.download_button("🖼️ Hindi Image", data=img_file, file_name="hindi_medicine_analysis.png", mime="image/png")
303
-
304
- # if response and st.button("🌐 Translate to Hindi"):
305
- # with st.spinner("Translating to Hindi..."):
306
- # chunks = split_text_into_chunks(response, max_length=100)
307
- # hindi_chunks = []
308
- # for chunk in chunks:
309
- # try:
310
- # translated = GoogleTranslator(source='auto', target='hi').translate(chunk)
311
- # hindi_chunks.append(translated)
312
- # except Exception as e:
313
- # hindi_chunks.append("[Error translating chunk]")
314
- # hindi_text = "\n\n".join(hindi_chunks)
315
 
316
  # st.markdown("#### 🌐 Hindi Translation")
317
- # st.text_area("Translated Output (Hindi)", hindi_text, height=600)
318
 
319
  # hindi_img_path = "hindi_output.png"
320
- # save_text_as_image(hindi_text, hindi_img_path)
321
 
322
  # st.markdown("#### 📥 Download (Hindi)")
323
  # col3, col4 = st.columns(2)
324
  # with col3:
325
- # st.download_button("⬇️ Hindi TXT", data=hindi_text.encode(), file_name="hindi_medicine_analysis.txt")
326
  # with col4:
327
  # with open(hindi_img_path, "rb") as img_file:
328
  # st.download_button("🖼️ Hindi Image", data=img_file, file_name="hindi_medicine_analysis.png", mime="image/png")
 
329
 
330
  try:
331
  os.remove(orig_path)
 
261
 
262
 
263
 
264
+ # if filtered_output and st.button("🌐 Translate to Hindi"):
265
+ # with st.spinner("Translating to Hindi..."):
 
 
 
 
 
 
 
 
266
 
267
+ # def clean_text(text):
268
+ # text = text.replace("•", "-") # Replace bullets
269
+ # text = re.sub(r"\s{2,}", " ", text) # Remove extra spaces
270
+ # text = re.sub(r"[^\w\s,.:-]", "", text) # Keep only safe characters
271
+ # return text
272
 
273
+ # cleaned_output = clean_text(filtered_output)
 
274
 
275
+ # try:
276
+ # hindi_text = GoogleTranslator(source='en', target='hi').translate(cleaned_output)
277
+ # except Exception as e:
278
+ # hindi_text = "[Translation failed]"
279
 
280
+ # # Formatting translated text
281
+ # formatted_text = re.sub(r'(?<=\s)-\s', r'\n- ', hindi_text)
282
 
283
+ # # Add line breaks before keywords
284
+ # keywords = ["खुराक और समय", "साइड इफेक्ट्स", "विशेष निर्देश"]
285
+ # for kw in keywords:
286
+ # formatted_text = formatted_text.replace(f"- {kw}", f"\n - {kw}")
287
 
288
+ # final_text = formatted_text.strip()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
289
 
290
  # st.markdown("#### 🌐 Hindi Translation")
291
+ # st.text_area("Translated Output (Hindi)", value=final_text, height=300)
292
 
293
  # hindi_img_path = "hindi_output.png"
294
+ # save_text_as_image(final_text, hindi_img_path)
295
 
296
  # st.markdown("#### 📥 Download (Hindi)")
297
  # col3, col4 = st.columns(2)
298
  # with col3:
299
+ # st.download_button("⬇️ Hindi TXT", data=final_text.encode(), file_name="hindi_medicine_analysis.txt")
300
  # with col4:
301
  # with open(hindi_img_path, "rb") as img_file:
302
  # st.download_button("🖼️ Hindi Image", data=img_file, file_name="hindi_medicine_analysis.png", mime="image/png")
303
+
304
 
305
  try:
306
  os.remove(orig_path)