Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| import os | |
| import requests | |
| API_TOKEN = os.getenv("HF_READ_TOKEN") | |
| headers = {"Authorization": f"Bearer {API_TOKEN}"} | |
| def gen(prompt, model='gpt'): | |
| if prompt == "" or prompt == None: | |
| return None | |
| if model == 'gpt': | |
| API_URL = "https://api-inference.huggingface.co/models/openchat/openchat_3.5" | |
| payload = { | |
| "inputs": prompt | |
| } | |
| response = requests.post(API_URL, headers=headers, json=payload) | |
| if response.status_code != 200: | |
| print(f"Ошибка: Не удалось получить ответ. Статус ответа: {response.status_code}") | |
| print(f"Содержимое ответа: {response.text}") | |
| return f"Произошла ошибка ({response.text})" | |
| return response.json() | |
| css = """ | |
| footer {visibility: hidden !important;} | |
| """ | |
| with gr.Blocks(css=css) as ui: | |
| with gr.Tab("Генерация"): | |
| with gr.Row(): | |
| prompt = gr.Textbox(label="Prompt", lines=3) | |
| with gr.Tab("Параметры"): | |
| with gr.Row(): | |
| gr.Markdown("## Скоро...") | |
| text_button = gr.Button("Генерация", variant='primary', elem_id="generate") | |
| text_output = gr.Textbox(show_label=False, placeholder="Привет! Чем я могу вам помочь?") | |
| text_button.click(gen, inputs=[prompt], outputs=text_output) | |
| #end | |
| ui.queue(api_open=False).launch() |