Spaces:
Sleeping
Sleeping
File size: 2,424 Bytes
d836ac3 007b4ac d836ac3 4431756 7c9c02d d836ac3 |
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 |
# 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."
)
|