File size: 2,952 Bytes
c5bc4ec
 
19df4a4
66fe08f
19df4a4
 
c5bc4ec
 
 
 
 
 
 
19df4a4
 
 
 
 
 
 
 
 
 
 
 
 
 
9a52147
 
 
 
 
 
 
 
 
 
 
aa4ffc9
9a52147
 
4710e5d
36ac934
 
 
a24aa43
 
 
904130c
36ac934
 
 
 
a24aa43
36ac934
4710e5d
 
 
 
 
 
a24aa43
36ac934
66fe08f
c5bc4ec
e9ee91c
c5bc4ec
bd58b49
c5bc4ec
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import gradio as gr
import os
import requests
import json

API_KEY = os.getenv("access_token")

def respond(
    message,
    max_tokens,
    temperature,
    top_p
):
    response = requests.post(
    url="https://api.featherless.ai/v1/completions",
    headers={
        "Authorization": f"Bearer {API_KEY}",
        "Content-type": "application/json"
    },
    json={
        "model": "Qwen/Qwen3-8B", 
        "prompt": message,
        "max_tokens": max_tokens,
        "temperature": temperature,
        "top_p": top_p
    }
)
    if response.status_code == 200:
        return response.json()["choices"][0]["text"]
    elif response.status_code == 429:
        try:
            output = response.json()
            return f"Error: {output['error']['code']}. Try submit your request again in a few seconds."
        except requests.exceptions.JSONDecodeError as e:
            return f"Error: {response}. Refresh the page and try again later, post the error on OLAT forum if your issue persists."
    else:
        try:
            output = response.json()
            return f"Error: {output['error']['message']}. Refresh the page and try again later, post the error on OLAT forum if your issue persists."
        except requests.exceptions.JSONDecodeError as e:
            return f"Error: {response}. Refresh the page and try again later, post the error on OLAT forum if your issue persists."

demo = gr.Interface(
    fn=respond,
    title="Text Generation Playground",
    description="""Model: Qwen/Qwen3-8B, Max input length: 1500 characters\n
Longer prompts take more time to process and may lead to timeouts or errors, Please keep your prompt short and concise.\n
Prompts longer than 1500 characters will be truncated, which may lead to incomplete or unexpected responses.\n
Try again or refresh the page if you encounter an error.""",
    inputs=[
        gr.Textbox(
            lines=15,
            label="Input Prompt",
            max_length=1500,
            placeholder="""Copy-Paste your own alignment prompt here:
E.g. # System-level prompt: You are a helpful assistant...\n
# Query: Who painted the Mona Lisa?\n
# Answer: The Mona Lisa was painted by Leonardo da Vinci, an Italian Renaissance artist, between 1503 and 1506, though some believe he may have continued working on it until 1517. It is one of the most famous and iconic works of art in history, known for its enigmatic expression and masterful technique.\n
# Query: ...\n
# Answer: 

# **Due to the limitations of the service, keep your prompt under 1500 characters.**""",
        ),
        gr.Slider(minimum=1, maximum=300, value=150, step=1, label="Max new tokens"),
        gr.Slider(minimum=0, maximum=2.0, value=1, step=0.01, label="Temperature"),
        gr.Slider(minimum=0.1, maximum=1.0, value=0.95, step=0.05,label="Top-p (nucleus sampling)"),
    ],
    outputs=gr.Textbox(lines=20, label="Response")
)


if __name__ == "__main__":
    demo.launch()