Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,4 +1,3 @@
|
|
| 1 |
-
from transformers import M2M100ForConditionalGeneration, M2M100Tokenizer
|
| 2 |
from transformers import MBartForConditionalGeneration, MBart50Tokenizer, pipeline
|
| 3 |
import gradio as gr
|
| 4 |
import requests
|
|
@@ -12,7 +11,7 @@ model_name = "facebook/mbart-large-50-many-to-one-mmt"
|
|
| 12 |
tokenizer = MBart50Tokenizer.from_pretrained(model_name)
|
| 13 |
model = MBartForConditionalGeneration.from_pretrained(model_name)
|
| 14 |
|
| 15 |
-
# Use GPT-2 for text generation instead of
|
| 16 |
text_gen_model = "gpt2"
|
| 17 |
pipe = pipeline(
|
| 18 |
"text-generation",
|
|
@@ -23,7 +22,7 @@ pipe = pipeline(
|
|
| 23 |
|
| 24 |
# Use the Hugging Face API key from environment variables for text-to-image model
|
| 25 |
API_URL = "https://api-inference.huggingface.co/models/ZB-Tech/Text-to-Image"
|
| 26 |
-
headers = {"Authorization": f"Bearer {os.getenv('
|
| 27 |
|
| 28 |
# Define the translation, text generation, and image generation function
|
| 29 |
def translate_and_generate_image(tamil_text):
|
|
@@ -34,7 +33,7 @@ def translate_and_generate_image(tamil_text):
|
|
| 34 |
translated_text = tokenizer.batch_decode(translated_tokens, skip_special_tokens=True)[0]
|
| 35 |
|
| 36 |
# Step 2: Generate descriptive English text using GPT-2
|
| 37 |
-
generated_text = pipe(translated_text, max_length=
|
| 38 |
|
| 39 |
# Step 3: Use the generated English text to create an image
|
| 40 |
def query(payload):
|
|
@@ -58,5 +57,5 @@ iface = gr.Interface(
|
|
| 58 |
description="Translate Tamil text to English using Facebook's mbart-large-50 model, generate descriptive text using GPT-2, and create an image using the generated text.",
|
| 59 |
)
|
| 60 |
|
| 61 |
-
# Launch Gradio app
|
| 62 |
-
iface.launch(
|
|
|
|
|
|
|
| 1 |
from transformers import MBartForConditionalGeneration, MBart50Tokenizer, pipeline
|
| 2 |
import gradio as gr
|
| 3 |
import requests
|
|
|
|
| 11 |
tokenizer = MBart50Tokenizer.from_pretrained(model_name)
|
| 12 |
model = MBartForConditionalGeneration.from_pretrained(model_name)
|
| 13 |
|
| 14 |
+
# Use GPT-2 for text generation instead of restricted models
|
| 15 |
text_gen_model = "gpt2"
|
| 16 |
pipe = pipeline(
|
| 17 |
"text-generation",
|
|
|
|
| 22 |
|
| 23 |
# Use the Hugging Face API key from environment variables for text-to-image model
|
| 24 |
API_URL = "https://api-inference.huggingface.co/models/ZB-Tech/Text-to-Image"
|
| 25 |
+
headers = {"Authorization": f"Bearer {os.getenv('full_token')}"}
|
| 26 |
|
| 27 |
# Define the translation, text generation, and image generation function
|
| 28 |
def translate_and_generate_image(tamil_text):
|
|
|
|
| 33 |
translated_text = tokenizer.batch_decode(translated_tokens, skip_special_tokens=True)[0]
|
| 34 |
|
| 35 |
# Step 2: Generate descriptive English text using GPT-2
|
| 36 |
+
generated_text = pipe(translated_text, max_length=50, num_return_sequences=1, truncation=True)[0]['generated_text']
|
| 37 |
|
| 38 |
# Step 3: Use the generated English text to create an image
|
| 39 |
def query(payload):
|
|
|
|
| 57 |
description="Translate Tamil text to English using Facebook's mbart-large-50 model, generate descriptive text using GPT-2, and create an image using the generated text.",
|
| 58 |
)
|
| 59 |
|
| 60 |
+
# Launch Gradio app without `share=True` (Hugging Face Spaces already handles sharing)
|
| 61 |
+
iface.launch()
|