Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| from transformers import pipeline | |
| import time | |
| # Простая функция для тестирования | |
| def analyze_coffee_sentiment(text): | |
| if not text or not text.strip(): | |
| return "⚠️ Введите текст отзыва о кофе", "0ms" | |
| try: | |
| start_time = time.time() | |
| # Используем легкую модель для быстрого старта | |
| classifier = pipeline( | |
| "sentiment-analysis", | |
| model="distilbert-base-uncased-finetuned-sst-2-english" | |
| ) | |
| result = classifier(text[:500])[0] | |
| latency = f"{(time.time() - start_time)*1000:.0f}ms" | |
| sentiment = "😊 Позитивный" if result['label'] == "POSITIVE" else "😞 Негативный" | |
| confidence = f"{result['score']:.1%}" | |
| return f"{sentiment} (уверенность: {confidence})", latency | |
| except Exception as e: | |
| return f"❌ Ошибка: {str(e)}", "0ms" | |
| # Минимальный интерфейс | |
| with gr.Blocks(title="Анализатор тональности кофе") as demo: | |
| gr.Markdown("# ☕ Анализатор тональности отзывов о кофе") | |
| with gr.Row(): | |
| text_input = gr.Textbox( | |
| label="Введите отзыв о кофе", | |
| placeholder="Пример: Этот кофе имеет богатый аромат...", | |
| lines=3 | |
| ) | |
| analyze_btn = gr.Button("Анализировать", variant="primary") | |
| with gr.Row(): | |
| result_output = gr.Textbox(label="Результат") | |
| time_output = gr.Textbox(label="Время выполнения") | |
| # Примеры | |
| gr.Examples( | |
| examples=[ | |
| ["This coffee is absolutely amazing! Best I've ever had."], | |
| ["Кофе был холодным и безвкусным. Очень разочарован."], | |
| ["Standard coffee, nothing special. Acceptable for the price."] | |
| ], | |
| inputs=text_input | |
| ) | |
| analyze_btn.click( | |
| fn=analyze_coffee_sentiment, | |
| inputs=text_input, | |
| outputs=[result_output, time_output] | |
| ) | |
| if __name__ == "__main__": | |
| demo.launch(debug=False) |