gokilashree commited on
Commit
9f045ce
·
verified ·
1 Parent(s): af0cc42

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -5
app.py CHANGED
@@ -33,7 +33,7 @@ def generate_image_from_text(translated_text):
33
  try:
34
  print(f"Generating image from translated text: {translated_text}")
35
  response = requests.post(API_URL, headers=headers, json={"inputs": translated_text})
36
-
37
  # Check if the response is successful
38
  if response.status_code != 200:
39
  print(f"Error generating image: {response.text}")
@@ -52,8 +52,14 @@ def generate_image_from_text(translated_text):
52
  def generate_short_paragraph_from_text(translated_text):
53
  try:
54
  print(f"Generating a short paragraph from translated text: {translated_text}")
55
- # Generate a shorter paragraph from the translated text using smaller settings
56
- paragraph = text_generator(translated_text, max_length=80, num_return_sequences=1, temperature=0.6, top_p=0.8)[0]['generated_text']
 
 
 
 
 
 
57
  print(f"Paragraph generation completed: {paragraph}")
58
  return paragraph
59
  except Exception as e:
@@ -85,7 +91,7 @@ def translate_generate_paragraph_and_image(tamil_text):
85
 
86
  return translated_text, paragraph, image, None
87
 
88
- # Gradio interface setup
89
  iface = gr.Interface(
90
  fn=translate_generate_paragraph_and_image,
91
  inputs=gr.Textbox(lines=2, placeholder="Enter Tamil text here..."),
@@ -94,7 +100,8 @@ iface = gr.Interface(
94
  gr.Image(label="Generated Image")],
95
  title="Tamil to English Translation, Short Paragraph Generation, and Image Creation",
96
  description="Translate Tamil text to English using Facebook's mbart-large-50 model, generate a short paragraph, and create an image using the translated text.",
 
97
  )
98
 
99
-
100
  iface.launch()
 
33
  try:
34
  print(f"Generating image from translated text: {translated_text}")
35
  response = requests.post(API_URL, headers=headers, json={"inputs": translated_text})
36
+
37
  # Check if the response is successful
38
  if response.status_code != 200:
39
  print(f"Error generating image: {response.text}")
 
52
  def generate_short_paragraph_from_text(translated_text):
53
  try:
54
  print(f"Generating a short paragraph from translated text: {translated_text}")
55
+ paragraph = text_generator(
56
+ translated_text,
57
+ max_length=80, # Reduced to 80 tokens
58
+ num_return_sequences=1,
59
+ temperature=0.6,
60
+ top_p=0.8,
61
+ truncation=True # Added truncation to avoid long sequences
62
+ )[0]['generated_text']
63
  print(f"Paragraph generation completed: {paragraph}")
64
  return paragraph
65
  except Exception as e:
 
91
 
92
  return translated_text, paragraph, image, None
93
 
94
+ # Gradio interface setup with share=True to make the app public
95
  iface = gr.Interface(
96
  fn=translate_generate_paragraph_and_image,
97
  inputs=gr.Textbox(lines=2, placeholder="Enter Tamil text here..."),
 
100
  gr.Image(label="Generated Image")],
101
  title="Tamil to English Translation, Short Paragraph Generation, and Image Creation",
102
  description="Translate Tamil text to English using Facebook's mbart-large-50 model, generate a short paragraph, and create an image using the translated text.",
103
+ share=True # Enable public sharing
104
  )
105
 
106
+ # Launch the app with the share option
107
  iface.launch()