root commited on
Commit
dee2bb2
·
1 Parent(s): 33fc7eb
Files changed (2) hide show
  1. app.py +118 -0
  2. requirements.txt +2 -0
app.py ADDED
@@ -0,0 +1,118 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import gradio as gr
3
+ from huggingface_hub import InferenceClient
4
+
5
+ MODEL_ID = "play451/Moron"
6
+ HF_TOKEN = os.getenv("HF_TOKEN") or os.getenv("HUGGINGFACEHUB_API_TOKEN")
7
+
8
+ client = InferenceClient(
9
+ model=MODEL_ID,
10
+ token=HF_TOKEN,
11
+ )
12
+
13
+ def generate(prompt, max_tokens, temperature, top_p):
14
+ """Generate a response from play451/Moron."""
15
+ prompt = (prompt or "").strip()
16
+ if not prompt:
17
+ return "Please enter a prompt."
18
+
19
+ try:
20
+ result = client.text_generation(
21
+ prompt,
22
+ max_new_tokens=int(max_tokens),
23
+ temperature=float(temperature),
24
+ top_p=float(top_p),
25
+ do_sample=True,
26
+ return_full_text=False,
27
+ )
28
+ return result
29
+ except Exception as e:
30
+ return (
31
+ "Inference failed.\n\n"
32
+ f"{type(e).__name__}: {e}\n\n"
33
+ "If the model requires authenticated inference, add an HF_TOKEN "
34
+ "secret in the Space settings."
35
+ )
36
+
37
+ examples = [
38
+ ["Hello! Introduce yourself."],
39
+ ["Write a short explanation of what you can do."],
40
+ ["Give me a creative idea for a Minecraft mod."],
41
+ ]
42
+
43
+ with gr.Blocks(
44
+ title="play451/Moron Demo",
45
+ theme=gr.themes.Soft(),
46
+ ) as demo:
47
+ gr.Markdown(
48
+ """
49
+ # 🤖 play451/Moron
50
+
51
+ Interactive demo for **[play451/Moron](https://huggingface.co/play451/Moron)**.
52
+
53
+ Enter a prompt below and generate text with the model.
54
+ """
55
+ )
56
+
57
+ with gr.Row():
58
+ with gr.Column(scale=2):
59
+ prompt = gr.Textbox(
60
+ label="Prompt",
61
+ placeholder="Enter your prompt...",
62
+ lines=8,
63
+ )
64
+
65
+ with gr.Row():
66
+ generate_btn = gr.Button("Generate", variant="primary")
67
+ clear_btn = gr.ClearButton([prompt])
68
+
69
+ with gr.Column(scale=2):
70
+ output = gr.Textbox(
71
+ label="Generated text",
72
+ lines=14,
73
+ show_copy_button=True,
74
+ )
75
+
76
+ with gr.Accordion("Generation settings", open=False):
77
+ max_tokens = gr.Slider(
78
+ minimum=16,
79
+ maximum=2048,
80
+ value=512,
81
+ step=1,
82
+ label="Max new tokens",
83
+ )
84
+ temperature = gr.Slider(
85
+ minimum=0.1,
86
+ maximum=2.0,
87
+ value=0.7,
88
+ step=0.05,
89
+ label="Temperature",
90
+ )
91
+ top_p = gr.Slider(
92
+ minimum=0.1,
93
+ maximum=1.0,
94
+ value=0.9,
95
+ step=0.05,
96
+ label="Top-p",
97
+ )
98
+
99
+ gr.Examples(
100
+ examples=examples,
101
+ inputs=prompt,
102
+ label="Examples",
103
+ )
104
+
105
+ generate_btn.click(
106
+ fn=generate,
107
+ inputs=[prompt, max_tokens, temperature, top_p],
108
+ outputs=output,
109
+ )
110
+
111
+ prompt.submit(
112
+ fn=generate,
113
+ inputs=[prompt, max_tokens, temperature, top_p],
114
+ outputs=output,
115
+ )
116
+
117
+ if __name__ == "__main__":
118
+ demo.launch()
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ huggingface_hub>=0.34.0
2
+