Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,14 +1,13 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import pipeline
|
| 3 |
from langdetect import detect
|
| 4 |
-
import os
|
| 5 |
|
| 6 |
-
#
|
| 7 |
generator = pipeline("text-generation", model="gpt2")
|
| 8 |
bg_to_en = pipeline("translation", model="Helsinki-NLP/opus-mt-bg-en")
|
| 9 |
en_to_bg = pipeline("translation", model="Helsinki-NLP/opus-mt-en-bg")
|
| 10 |
|
| 11 |
-
NUM_THREADS = 2
|
| 12 |
|
| 13 |
def generate_response(user_input, top_p, temperature, chat_counter, chatbot, history, request: gr.Request):
|
| 14 |
lang = detect(user_input)
|
|
@@ -39,6 +38,26 @@ def generate_response(user_input, top_p, temperature, chat_counter, chatbot, his
|
|
| 39 |
def reset_textbox():
|
| 40 |
return gr.update(value='', interactive=False), gr.update(interactive=False)
|
| 41 |
|
| 42 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
|
| 44 |
-
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import pipeline
|
| 3 |
from langdetect import detect
|
|
|
|
| 4 |
|
| 5 |
+
# Load models
|
| 6 |
generator = pipeline("text-generation", model="gpt2")
|
| 7 |
bg_to_en = pipeline("translation", model="Helsinki-NLP/opus-mt-bg-en")
|
| 8 |
en_to_bg = pipeline("translation", model="Helsinki-NLP/opus-mt-en-bg")
|
| 9 |
|
| 10 |
+
NUM_THREADS = 2
|
| 11 |
|
| 12 |
def generate_response(user_input, top_p, temperature, chat_counter, chatbot, history, request: gr.Request):
|
| 13 |
lang = detect(user_input)
|
|
|
|
| 38 |
def reset_textbox():
|
| 39 |
return gr.update(value='', interactive=False), gr.update(interactive=False)
|
| 40 |
|
| 41 |
+
with gr.Blocks(theme=gr.themes.Default()) as demo:
|
| 42 |
+
gr.Markdown("""
|
| 43 |
+
# 🛍️ MasterBrand AI Assistant
|
| 44 |
+
Ask me anything about your e-commerce store – in English or Bulgarian.
|
| 45 |
+
""")
|
| 46 |
+
|
| 47 |
+
chatbot = gr.Chatbot()
|
| 48 |
+
inputs = gr.Textbox(placeholder="What product should I sell?", label="Your question")
|
| 49 |
+
state = gr.State([])
|
| 50 |
+
chat_counter = gr.Number(value=0, visible=False)
|
| 51 |
+
top_p = gr.Slider(minimum=0.1, maximum=1.0, value=0.9, step=0.05, label="Top-p (creativity)")
|
| 52 |
+
temperature = gr.Slider(minimum=0.1, maximum=2.0, value=1.0, step=0.1, label="Temperature")
|
| 53 |
+
|
| 54 |
+
with gr.Row():
|
| 55 |
+
submit_btn = gr.Button("🚀 Ask")
|
| 56 |
+
status_box = gr.Textbox(label="Status", interactive=False)
|
| 57 |
+
|
| 58 |
+
inputs.submit(reset_textbox, [], [inputs, submit_btn], queue=False)
|
| 59 |
+
inputs.submit(generate_response, [inputs, top_p, temperature, chat_counter, chatbot, state], [chatbot, state, chat_counter, status_box, inputs, submit_btn])
|
| 60 |
+
submit_btn.click(reset_textbox, [], [inputs, submit_btn], queue=False)
|
| 61 |
+
submit_btn.click(generate_response, [inputs, top_p, temperature, chat_counter, chatbot, state], [chatbot, state, chat_counter, status_box, inputs, submit_btn])
|
| 62 |
|
| 63 |
+
demo.queue(max_size=10).launch()
|