Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,36 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
-
import random
|
| 3 |
-
from datasets import load_dataset
|
| 4 |
-
from transformers import pipeline
|
| 5 |
-
|
| 6 |
-
# Load Hindi Poetry Dataset
|
| 7 |
-
dataset = load_dataset("rahul7star/hindi-poetry")
|
| 8 |
-
poems = dataset["train"]
|
| 9 |
-
|
| 10 |
-
def get_random_poem():
|
| 11 |
-
poem = random.choice(poems)
|
| 12 |
-
return f"**{poem['poet']} ({poem['category']})**\n\n{poem['poem']}"
|
| 13 |
-
|
| 14 |
-
# Load Text Generation Model
|
| 15 |
-
# Load Text Generation Model
|
| 16 |
-
text_generator = pipeline("text-generation", model="rahul7star/hindi_poetry_language_model")
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
def generate_poem(prompt):
|
| 20 |
-
result = text_generator(prompt, max_length=100, do_sample=True, temperature=0.7)
|
| 21 |
-
return result[0]["generated_text"]
|
| 22 |
-
|
| 23 |
-
# Gradio UI
|
| 24 |
-
demo = gr.Interface(
|
| 25 |
-
title="📜 हिंदी कविता जनरेटर",
|
| 26 |
-
description="देखें हिंदी कविताएँ और अपनी खुद की कविता बनाएं!",
|
| 27 |
-
theme="huggingface",
|
| 28 |
-
fn=generate_poem,
|
| 29 |
-
inputs=gr.Textbox(placeholder="अपनी कविता की शुरुआत लिखें...", label="कविता की शुरुआत"),
|
| 30 |
-
outputs=gr.Textbox(label="उत्पन्न कविता"),
|
| 31 |
-
examples=[["प्रकृति की सुंदरता"], ["प्रेम की निशानी"]],
|
| 32 |
-
live=True
|
| 33 |
-
)
|
| 34 |
|
| 35 |
-
|
| 36 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# import gradio as gr
|
| 2 |
+
# import random
|
| 3 |
+
# from datasets import load_dataset
|
| 4 |
+
# from transformers import pipeline
|
| 5 |
+
|
| 6 |
+
# # Load Hindi Poetry Dataset
|
| 7 |
+
# dataset = load_dataset("rahul7star/hindi-poetry")
|
| 8 |
+
# poems = dataset["train"]
|
| 9 |
+
|
| 10 |
+
# def get_random_poem():
|
| 11 |
+
# poem = random.choice(poems)
|
| 12 |
+
# return f"**{poem['poet']} ({poem['category']})**\n\n{poem['poem']}"
|
| 13 |
+
|
| 14 |
+
# # Load Text Generation Model
|
| 15 |
+
# # Load Text Generation Model
|
| 16 |
+
# text_generator = pipeline("text-generation", model="rahul7star/hindi_poetry_language_model")
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
# def generate_poem(prompt):
|
| 20 |
+
# result = text_generator(prompt, max_length=100, do_sample=True, temperature=0.7)
|
| 21 |
+
# return result[0]["generated_text"]
|
| 22 |
+
|
| 23 |
+
# # Gradio UI
|
| 24 |
+
# demo = gr.Interface(
|
| 25 |
+
# title="📜 हिंदी कविता जनरेटर",
|
| 26 |
+
# description="देखें हिंदी कविताएँ और अपनी खुद की कविता बनाएं!",
|
| 27 |
+
# theme="huggingface",
|
| 28 |
+
# fn=generate_poem,
|
| 29 |
+
# inputs=gr.Textbox(placeholder="अपनी कविता की शुरुआत लिखें...", label="कविता की शुरुआत"),
|
| 30 |
+
# outputs=gr.Textbox(label="उत्पन्न कविता"),
|
| 31 |
+
# examples=[["प्रकृति की सुंदरता"], ["प्रेम की निशानी"]],
|
| 32 |
+
# live=True
|
| 33 |
+
# )
|
| 34 |
+
|
| 35 |
+
# # Add button to display a random poem
|
| 36 |
+
# demo.launch(share=True)
|
| 37 |
+
|
| 38 |
+
# Download model and tokenizer from HF
|
| 39 |
+
model_path = hf_hub_download("rahul7star/hindi_poetry_language_model", filename="model.pkl")
|
| 40 |
+
#tokenizer_path = hf_hub_download("rahul7star/Rahul-FineTunedLLM-v03", filename="tokenizer/tokenizer.pkl")
|
| 41 |
+
|
| 42 |
+
# Load the learner from Hugging Face
|
| 43 |
+
learn = load_learner(model_path)
|
| 44 |
+
|
| 45 |
+
# Step 9: Define Gradio interface to generate poems based on theme
|
| 46 |
+
def generate_poem_gradio(theme):
|
| 47 |
+
# Generate a poem based on the theme input
|
| 48 |
+
text = learn.predict(theme)[0]
|
| 49 |
+
return text
|
| 50 |
+
|
| 51 |
+
# Define the Gradio interface
|
| 52 |
import gradio as gr
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 53 |
|
| 54 |
+
iface = gr.Interface(
|
| 55 |
+
fn=generate_poem_gradio, # Function to call for generating poems
|
| 56 |
+
inputs="text", # User input will be a text field (theme)
|
| 57 |
+
outputs="text", # Output will be the generated poem
|
| 58 |
+
title="Hindi Poem Generator",
|
| 59 |
+
description="Enter a theme (in Hindi), and get a poem generated based on that theme."
|
| 60 |
+
)
|