Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# app.py
|
| 2 |
+
|
| 3 |
+
import gradio as gr
|
| 4 |
+
from handler import generate_text
|
| 5 |
+
|
| 6 |
+
def infer(prompt, max_tokens, temperature, top_p, top_k, repetition_penalty, trim_output):
|
| 7 |
+
return generate_text(
|
| 8 |
+
prompt,
|
| 9 |
+
max_tokens=max_tokens,
|
| 10 |
+
temperature=temperature,
|
| 11 |
+
top_p=top_p,
|
| 12 |
+
top_k=top_k,
|
| 13 |
+
repetition_penalty=repetition_penalty,
|
| 14 |
+
trim_output=trim_output
|
| 15 |
+
)
|
| 16 |
+
|
| 17 |
+
iface = gr.Interface(
|
| 18 |
+
fn=infer,
|
| 19 |
+
inputs=[
|
| 20 |
+
gr.Textbox(label="Prompt", placeholder="Type your prompt here...", lines=4),
|
| 21 |
+
gr.Slider(50, 512, step=10, value=250, label="Max Tokens"),
|
| 22 |
+
gr.Slider(0.1, 1.5, step=0.1, value=0.7, label="Temperature"),
|
| 23 |
+
gr.Slider(0.1, 1.0, step=0.05, value=0.95, label="Top-p (nucleus sampling)"),
|
| 24 |
+
gr.Slider(0, 100, step=1, value=50, label="Top-k"),
|
| 25 |
+
gr.Slider(0.5, 2.0, step=0.1, value=1.2, label="Repetition Penalty"),
|
| 26 |
+
gr.Checkbox(label="Trim Prompt From Output", value=True)
|
| 27 |
+
],
|
| 28 |
+
outputs=gr.Textbox(label="Generated Text", lines=10),
|
| 29 |
+
title="🧠 Your Custom AI Text Generator",
|
| 30 |
+
description="Using Hugging Face inference API with your own model (no token required)"
|
| 31 |
+
)
|
| 32 |
+
|
| 33 |
+
if __name__ == "__main__":
|
| 34 |
+
iface.launch()
|