Faizan Azizahmed Shaikh commited on
Commit
ffec71d
·
1 Parent(s): dae1618

Created app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -0
app.py ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python
2
+ # coding: utf-8
3
+
4
+ # importing required libraries
5
+ from transformers import pipeline
6
+ from torch import bfloat16
7
+ import gradio as gr
8
+ WARNING = """Whoooa there, partner! Before you dive in, let's establish some ground rules:\nBy using this application, you are stating that you are the 'Big Cheese', the 'Head Honcho', the 'Master of Your Domain', in short, the sole user of this app. Now, don't go blaming us or any other parties if the results are not to your liking, or lead to any unforeseen circumstances.\nIn the simplest terms, the moment you input any data on this page you accept full responsibility for any and all usage of this application. Just like when you eat that extra slice of pizza at midnight, you're the one who's responsible for the extra workout the next day, not the pizza guy!"""
9
+
10
+ # pipeline function with default values
11
+ def story(prompt="When I was young", model_name = "coffeeee/nsfw-story-generator2", story_length=300):
12
+ """
13
+ model_name: full model name to be used from the hugging face models, default: coffeeee/nsfw-story-generator2;
14
+ prompt: user input to to extend the story based on the prompt, default: 'When I was young';
15
+ story_length: number of maximum tokens to generate, function_default: 50, modified_default: 300;
16
+ """
17
+ # create a pipeline for the model
18
+ create = pipeline(model=model_name, torch_dtype=bfloat16, device_map="auto")
19
+ # return the output from the model
20
+ return create(prompt, max_new_tokens=story_length)[0]['generated_text']
21
+
22
+ # block framework to customize the io page
23
+ with gr.Blocks() as demo:
24
+ gr.Markdown("# Erotic Story Generator, a delightful combo of HuggingFace API and Gradio.io")
25
+ gr.Label(value=WARNING, label="Disclaimer!!!")
26
+ story_start = gr.Textbox(label="Begin the storyline", value="This is about the time when I was 15 years old and living with")
27
+ selected_model = gr.Textbox(value="coffeeee/nsfw-story-generator2", label="Hugging Face Model To Use")
28
+ story_len = gr.Slider(100,500, label="Arc length")
29
+ gen_story = gr.Textbox(label="Story", lines=15, max_lines=20)
30
+ greet_btn = gr.Button("Entertain")
31
+ greet_btn.click(fn=story, inputs=[story_start, selected_model, story_len], outputs=gen_story, api_name="story")
32
+ demo.launch(auth=("admin", "assignment3"), inline=False, share=True)