Create QUANTARION13-APP.PY
Browse files- QUANTARION13-APP.PY +58 -0
QUANTARION13-APP.PY
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import pipeline
|
| 3 |
+
|
| 4 |
+
# Model ID on Hugging Face
|
| 5 |
+
MODEL_ID = "Aqarion13/QUANTARION-EDU-AI"
|
| 6 |
+
|
| 7 |
+
# Create a text-generation pipeline
|
| 8 |
+
generator = pipeline(
|
| 9 |
+
"text-generation",
|
| 10 |
+
model=MODEL_ID,
|
| 11 |
+
tokenizer=MODEL_ID,
|
| 12 |
+
# You can adjust max_length if you want longer outputs
|
| 13 |
+
max_length=150
|
| 14 |
+
)
|
| 15 |
+
|
| 16 |
+
def generate_text(prompt: str, max_length: int = 150):
|
| 17 |
+
"""
|
| 18 |
+
Generate text from a prompt using the model.
|
| 19 |
+
"""
|
| 20 |
+
if not prompt:
|
| 21 |
+
return "Please enter a prompt."
|
| 22 |
+
|
| 23 |
+
# Generate output with sampling parameters
|
| 24 |
+
outputs = generator(
|
| 25 |
+
prompt,
|
| 26 |
+
max_length=max_length,
|
| 27 |
+
do_sample=True,
|
| 28 |
+
top_k=50,
|
| 29 |
+
top_p=0.95
|
| 30 |
+
)
|
| 31 |
+
|
| 32 |
+
# Return the generated text
|
| 33 |
+
return outputs[0]["generated_text"]
|
| 34 |
+
|
| 35 |
+
# Build Gradio UI
|
| 36 |
+
with gr.Blocks() as demo:
|
| 37 |
+
gr.Markdown("# 🤖 QUANTARION Text Generation")
|
| 38 |
+
gr.Markdown(
|
| 39 |
+
"Enter a prompt below to generate text in English, Hindi, Chinese, or Spanish."
|
| 40 |
+
)
|
| 41 |
+
|
| 42 |
+
prompt_input = gr.Textbox(label="Input Prompt", lines=3)
|
| 43 |
+
max_length_input = gr.Slider(
|
| 44 |
+
minimum=50, maximum=500, step=10,
|
| 45 |
+
label="Max Output Length", value=150
|
| 46 |
+
)
|
| 47 |
+
generate_button = gr.Button("Generate")
|
| 48 |
+
output_text = gr.Textbox(label="Generated Text", lines=10)
|
| 49 |
+
|
| 50 |
+
# Bind UI interaction
|
| 51 |
+
generate_button.click(
|
| 52 |
+
fn=generate_text,
|
| 53 |
+
inputs=[prompt_input, max_length_input],
|
| 54 |
+
outputs=output_text,
|
| 55 |
+
)
|
| 56 |
+
|
| 57 |
+
if __name__ == "__main__":
|
| 58 |
+
demo.launch()
|