pravin0077 commited on
Commit
2816496
·
verified ·
1 Parent(s): 3a6b0f7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -13
app.py CHANGED
@@ -21,10 +21,10 @@ def translate_text(tamil_text):
21
  translation = translation_tokenizer.decode(translated_tokens[0], skip_special_tokens=True)
22
  return translation
23
 
24
- def query_gpt_neo(translated_text, max_words):
25
  prompt = f"Continue the story based on the following text: {translated_text}"
26
  inputs = gpt_tokenizer(prompt, return_tensors="pt")
27
- outputs = gpt_model.generate(inputs['input_ids'], max_length=max_words, num_return_sequences=1)
28
  creative_text = gpt_tokenizer.decode(outputs[0], skip_special_tokens=True)
29
  return creative_text
30
 
@@ -42,13 +42,13 @@ def query_image(payload):
42
  else:
43
  return f"Error: {response.status_code} - {response.text}"
44
 
45
- def process_input(tamil_input, max_words):
46
  try:
47
  # Translate the input text
48
  translated_output = translate_text(tamil_input)
49
 
50
  # Generate creative text using GPT-Neo
51
- creative_output = query_gpt_neo(translated_output, max_words)
52
 
53
  # Generate an image using Hugging Face's FLUX model
54
  image_bytes = query_image({"inputs": translated_output})
@@ -58,22 +58,17 @@ def process_input(tamil_input, max_words):
58
  except Exception as e:
59
  return f"Error occurred: {str(e)}", "", None
60
 
61
- # Create a Gradio interface with interactive elements
62
  interface = gr.Interface(
63
  fn=process_input,
64
- inputs=[
65
- gr.Textbox(label="Input Tamil Text", placeholder="Enter your Tamil text here..."),
66
- gr.Slider(label="Max Words for Creative Text", minimum=50, maximum=200, step=10, value=100)
67
- ],
68
  outputs=[
69
  gr.Textbox(label="Translated Text"),
70
  gr.Textbox(label="Creative Text"),
71
  gr.Image(label="Generated Image")
72
  ],
73
- title="TRANSART - Multimodal AI App",
74
- description="Enter Tamil text to translate to English, generate creative text, and produce an image based on the translated text.",
75
- theme="compact", # Use the 'compact' theme for a cleaner app look
76
- layout="vertical" # Arrange components vertically for better readability
77
  )
78
 
79
  interface.launch()
 
21
  translation = translation_tokenizer.decode(translated_tokens[0], skip_special_tokens=True)
22
  return translation
23
 
24
+ def query_gpt_neo(translated_text):
25
  prompt = f"Continue the story based on the following text: {translated_text}"
26
  inputs = gpt_tokenizer(prompt, return_tensors="pt")
27
+ outputs = gpt_model.generate(inputs['input_ids'], max_length=100, num_return_sequences=1)
28
  creative_text = gpt_tokenizer.decode(outputs[0], skip_special_tokens=True)
29
  return creative_text
30
 
 
42
  else:
43
  return f"Error: {response.status_code} - {response.text}"
44
 
45
+ def process_input(tamil_input):
46
  try:
47
  # Translate the input text
48
  translated_output = translate_text(tamil_input)
49
 
50
  # Generate creative text using GPT-Neo
51
+ creative_output = query_gpt_neo(translated_output)
52
 
53
  # Generate an image using Hugging Face's FLUX model
54
  image_bytes = query_image({"inputs": translated_output})
 
58
  except Exception as e:
59
  return f"Error occurred: {str(e)}", "", None
60
 
61
+ # Create a Gradio interface
62
  interface = gr.Interface(
63
  fn=process_input,
64
+ inputs=[gr.Textbox(label="Input Tamil Text")],
 
 
 
65
  outputs=[
66
  gr.Textbox(label="Translated Text"),
67
  gr.Textbox(label="Creative Text"),
68
  gr.Image(label="Generated Image")
69
  ],
70
+ title="TRANSART",
71
+ description="Enter Tamil text to translate to English and generate an image based on the translated text."
 
 
72
  )
73
 
74
  interface.launch()