Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -4,19 +4,19 @@ import requests
|
|
4 |
import io
|
5 |
from PIL import Image
|
6 |
import os
|
7 |
-
import torch
|
8 |
|
9 |
# Load the translation model and tokenizer
|
10 |
model_name = "facebook/mbart-large-50-many-to-one-mmt"
|
11 |
tokenizer = MBart50Tokenizer.from_pretrained(model_name)
|
12 |
model = MBartForConditionalGeneration.from_pretrained(model_name)
|
13 |
|
14 |
-
# Use GPT-
|
15 |
-
text_gen_model = "
|
16 |
pipe = pipeline(
|
17 |
"text-generation",
|
18 |
model=text_gen_model,
|
19 |
-
torch_dtype=torch.
|
20 |
device_map="auto"
|
21 |
)
|
22 |
|
@@ -32,8 +32,17 @@ def translate_and_generate_image(tamil_text):
|
|
32 |
translated_tokens = model.generate(**inputs, forced_bos_token_id=tokenizer.lang_code_to_id["en_XX"])
|
33 |
translated_text = tokenizer.batch_decode(translated_tokens, skip_special_tokens=True)[0]
|
34 |
|
35 |
-
# Step 2: Generate descriptive English text using GPT-
|
36 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
37 |
|
38 |
# Step 3: Use the generated English text to create an image
|
39 |
def query(payload):
|
@@ -54,8 +63,8 @@ iface = gr.Interface(
|
|
54 |
gr.Textbox(label="Generated Descriptive Text"),
|
55 |
gr.Image(label="Generated Image")],
|
56 |
title="Tamil to English Translation, Text Generation, and Image Creation",
|
57 |
-
description="Translate Tamil text to English using Facebook's mbart-large-50 model, generate descriptive text using GPT-
|
58 |
)
|
59 |
|
60 |
-
# Launch Gradio app
|
61 |
iface.launch()
|
|
|
4 |
import io
|
5 |
from PIL import Image
|
6 |
import os
|
7 |
+
import torch
|
8 |
|
9 |
# Load the translation model and tokenizer
|
10 |
model_name = "facebook/mbart-large-50-many-to-one-mmt"
|
11 |
tokenizer = MBart50Tokenizer.from_pretrained(model_name)
|
12 |
model = MBartForConditionalGeneration.from_pretrained(model_name)
|
13 |
|
14 |
+
# Use GPT-Neo for more powerful text generation
|
15 |
+
text_gen_model = "EleutherAI/gpt-neo-1.3B" # Use EleutherAI/gpt-neo-2.7B for even better results
|
16 |
pipe = pipeline(
|
17 |
"text-generation",
|
18 |
model=text_gen_model,
|
19 |
+
torch_dtype=torch.float32,
|
20 |
device_map="auto"
|
21 |
)
|
22 |
|
|
|
32 |
translated_tokens = model.generate(**inputs, forced_bos_token_id=tokenizer.lang_code_to_id["en_XX"])
|
33 |
translated_text = tokenizer.batch_decode(translated_tokens, skip_special_tokens=True)[0]
|
34 |
|
35 |
+
# Step 2: Generate descriptive English text using GPT-Neo
|
36 |
+
prompt = f"Create a detailed description based on the following text: {translated_text}"
|
37 |
+
generated_text = pipe(
|
38 |
+
prompt,
|
39 |
+
max_length=100,
|
40 |
+
num_return_sequences=1,
|
41 |
+
temperature=0.7,
|
42 |
+
top_p=0.9,
|
43 |
+
top_k=50,
|
44 |
+
truncation=True
|
45 |
+
)[0]['generated_text']
|
46 |
|
47 |
# Step 3: Use the generated English text to create an image
|
48 |
def query(payload):
|
|
|
63 |
gr.Textbox(label="Generated Descriptive Text"),
|
64 |
gr.Image(label="Generated Image")],
|
65 |
title="Tamil to English Translation, Text Generation, and Image Creation",
|
66 |
+
description="Translate Tamil text to English using Facebook's mbart-large-50 model, generate descriptive text using GPT-Neo, and create an image using the generated text.",
|
67 |
)
|
68 |
|
69 |
+
# Launch Gradio app
|
70 |
iface.launch()
|