# import gradio as gr # import random # from datasets import load_dataset # from transformers import pipeline # # Load Hindi Poetry Dataset # dataset = load_dataset("rahul7star/hindi-poetry") # poems = dataset["train"] # def get_random_poem(): # poem = random.choice(poems) # return f"**{poem['poet']} ({poem['category']})**\n\n{poem['poem']}" # # Load Text Generation Model # # Load Text Generation Model # text_generator = pipeline("text-generation", model="rahul7star/hindi_poetry_language_model") # def generate_poem(prompt): # result = text_generator(prompt, max_length=100, do_sample=True, temperature=0.7) # return result[0]["generated_text"] # # Gradio UI # demo = gr.Interface( # title="ЁЯУЬ рд╣рд┐рдВрджреА рдХрд╡рд┐рддрд╛ рдЬрдирд░реЗрдЯрд░", # description="рджреЗрдЦреЗрдВ рд╣рд┐рдВрджреА рдХрд╡рд┐рддрд╛рдПрдБ рдФрд░ рдЕрдкрдиреА рдЦреБрдж рдХреА рдХрд╡рд┐рддрд╛ рдмрдирд╛рдПрдВ!", # theme="huggingface", # fn=generate_poem, # inputs=gr.Textbox(placeholder="рдЕрдкрдиреА рдХрд╡рд┐рддрд╛ рдХреА рд╢реБрд░реБрдЖрдд рд▓рд┐рдЦреЗрдВ...", label="рдХрд╡рд┐рддрд╛ рдХреА рд╢реБрд░реБрдЖрдд"), # outputs=gr.Textbox(label="рдЙрддреНрдкрдиреНрди рдХрд╡рд┐рддрд╛"), # examples=[["рдкреНрд░рдХреГрддрд┐ рдХреА рд╕реБрдВрджрд░рддрд╛"], ["рдкреНрд░реЗрдо рдХреА рдирд┐рд╢рд╛рдиреА"]], # live=True # ) # # Add button to display a random poem # demo.launch(share=True) import gradio as gr from fastai.text.all import load_learner from huggingface_hub import hf_hub_download # Download model and tokenizer from HF model_path = hf_hub_download("rahul7star/hindi_poetry_language_model", filename="model.pkl") #tokenizer_path = hf_hub_download("rahul7star/Rahul-FineTunedLLM-v03", filename="tokenizer/tokenizer.pkl") # Load the learner from Hugging Face learn = load_learner(model_path) # Step 9: Define Gradio interface to generate poems based on theme def generate_poem_gradio(theme): # Generate a poem based on the theme input text = learn.predict(theme)[0] return text # Define the Gradio interface import gradio as gr iface = gr.Interface( fn=generate_poem_gradio, # Function to call for generating poems inputs="text", # User input will be a text field (theme) outputs="text", # Output will be the generated poem title="Hindi Poem Generator", description="Enter a theme (in Hindi), and get a poem generated based on that theme." )