Spaces:
Sleeping
Sleeping
File size: 3,977 Bytes
3c5a557 653cf6d 6955ba9 653cf6d 6955ba9 653cf6d 841a7fd 653cf6d 841a7fd 653cf6d 6955ba9 653cf6d 6955ba9 653cf6d 3c5a557 653cf6d afea5f7 653cf6d 3c5a557 653cf6d 6955ba9 653cf6d 3c5a557 653cf6d 3c5a557 653cf6d 3c5a557 653cf6d 3c5a557 653cf6d 3c5a557 653cf6d 6955ba9 3c5a557 653cf6d | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 | import gradio as gr
from transformers import pipeline
import pandas as pd
import logging
# Set up logging
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
class FrenchTitleGenerator:
def __init__(self):
try:
# Load your fine-tuned model from Hugging Face
# Replace with your actual model name after training
self.generator = pipeline(
"translation",
model="sufya12/french-title-model", # Change this to your model
tokenizer="sufya12/french-title-model"
)
logger.info("✅ Model loaded successfully from Hugging Face")
except Exception as e:
logger.error(f"❌ Error loading model: {e}")
self.generator = None
def generate_title(self, year, city, event_description, temperature=0.8, max_length=60):
if not self.generator:
return "Error: Model not loaded. Please check the logs."
try:
# Create input prompt
input_text = f"Generate French title: Year: {year} City: {city} Event: {event_description}"
# Generate title
result = self.generator(
input_text,
max_length=max_length,
num_beams=3,
temperature=temperature,
do_sample=True,
early_stopping=True
)
return result[0]['translation_text']
except Exception as e:
return f"Error generating title: {str(e)}"
# Initialize the generator
title_generator = FrenchTitleGenerator()
# Gradio interface
def generate_french_title(year, city, event_description, temperature, max_length):
return title_generator.generate_title(year, city, event_description, temperature, max_length)
# Create the interface
with gr.Blocks(theme=gr.themes.Soft()) as demo:
gr.Markdown("# 🇫🇷 French Event Title Generator")
gr.Markdown("Generate professional French event titles using AI!")
with gr.Row():
with gr.Column():
year_input = gr.Textbox(
label="Year",
placeholder="e.g., 2025",
value="2025"
)
city_input = gr.Textbox(
label="City",
placeholder="e.g., Paris",
value="Paris"
)
event_input = gr.Textbox(
label="Event Description",
placeholder="Describe your event in English...",
lines=3
)
with gr.Row():
temperature_slider = gr.Slider(
minimum=0.1,
maximum=1.5,
value=0.8,
step=0.1,
label="Creativity Level"
)
max_length_slider = gr.Slider(
minimum=20,
maximum=100,
value=60,
step=5,
label="Title Length"
)
generate_btn = gr.Button("Generate Title 🚀", variant="primary")
with gr.Column():
output_text = gr.Textbox(
label="Generated French Title",
lines=4,
show_copy_button=True
)
# Examples
gr.Examples(
examples=[
["2025", "Paris", "Summer Jazz Festival in the Park"],
["2024", "Lyon", "International Food and Wine Exhibition"],
["2025", "Nice", "Beach Music Concert and Party"]
],
inputs=[year_input, city_input, event_input]
)
generate_btn.click(
fn=generate_french_title,
inputs=[year_input, city_input, event_input, temperature_slider, max_length_slider],
outputs=output_text
)
if __name__ == "__main__":
demo.launch() |