Turbiling commited on
Commit
6d090e8
·
verified ·
1 Parent(s): cd9d24c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -12
app.py CHANGED
@@ -1,6 +1,8 @@
1
  import os
2
  import gradio as gr
3
  from docx import Document
 
 
4
  import datetime
5
  from groq import Groq
6
  from huggingface_hub import InferenceClient
@@ -53,18 +55,17 @@ Include the following structured components only:
53
  """
54
 
55
  urdu_response = hf_client.text_generation(
56
- model="MuhammadYaseen77999/urdu-islamic-bot",
57
- prompt=prompt,
58
- max_new_tokens=600,
59
- temperature=0.7,
60
- )
61
-
62
- # Extract text properly
63
- if isinstance(urdu_response, str):
64
- lesson_text = urdu_response.strip()
65
- else:
66
- lesson_text = urdu_response.get("generated_text", "").strip()
67
 
 
 
 
 
 
68
 
69
  # Create Word document
70
  doc = Document()
@@ -88,7 +89,15 @@ else:
88
  row_cells[1].text = value
89
 
90
  doc.add_paragraph("\n")
91
- doc.add_paragraph(lesson_text)
 
 
 
 
 
 
 
 
92
  doc.add_paragraph("\nDeveloped by Najaf Ali Sharqi")
93
 
94
  filename = f"lesson_plan_{datetime.datetime.now().strftime('%Y%m%d%H%M%S')}.docx"
 
1
  import os
2
  import gradio as gr
3
  from docx import Document
4
+ from docx.oxml.ns import qn
5
+ from docx.oxml import OxmlElement
6
  import datetime
7
  from groq import Groq
8
  from huggingface_hub import InferenceClient
 
55
  """
56
 
57
  urdu_response = hf_client.text_generation(
58
+ model="MuhammadYaseen77999/urdu-islamic-bot",
59
+ prompt=prompt,
60
+ max_new_tokens=600,
61
+ temperature=0.7,
62
+ )
 
 
 
 
 
 
63
 
64
+ # Extract Urdu text properly
65
+ if isinstance(urdu_response, str):
66
+ lesson_text = urdu_response.strip()
67
+ else:
68
+ lesson_text = urdu_response.get("generated_text", "").strip()
69
 
70
  # Create Word document
71
  doc = Document()
 
89
  row_cells[1].text = value
90
 
91
  doc.add_paragraph("\n")
92
+
93
+ # Add right-to-left formatting for Urdu text
94
+ paragraph = doc.add_paragraph(lesson_text)
95
+ if language == "Urdu":
96
+ paragraph.alignment = 2 # Right alignment
97
+ rtl = OxmlElement('w:rtl')
98
+ rtl.set(qn('w:val'), '1')
99
+ paragraph._element.insert(0, rtl)
100
+
101
  doc.add_paragraph("\nDeveloped by Najaf Ali Sharqi")
102
 
103
  filename = f"lesson_plan_{datetime.datetime.now().strftime('%Y%m%d%H%M%S')}.docx"