Rooni commited on
Commit
9cecf78
·
1 Parent(s): b8fb0b0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +65 -0
app.py CHANGED
@@ -42,3 +42,68 @@ demo = gr.Interface(
42
  title="Text Generation Demo",
43
  css=css
44
  ).launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
42
  title="Text Generation Demo",
43
  css=css
44
  ).launch()
45
+
46
+
47
+
48
+
49
+
50
+
51
+
52
+
53
+
54
+ # imports
55
+ import gradio as gr
56
+ import requests
57
+ import json
58
+ import os
59
+ from deep_translator import GoogleTranslator
60
+ from langdetect import detect
61
+ from transformers import pipeline
62
+
63
+
64
+ # functions
65
+ def generate(promt, max_tokens):
66
+ if not description or not model:
67
+ return ""
68
+
69
+ language = detect(prompt)
70
+
71
+ if language == 'ru':
72
+ prompt = GoogleTranslator(source='ru', target='en').translate(prompt)
73
+ print(prompt)
74
+
75
+
76
+ output = generator(prompt, max_tokens)[0]['generated_text']
77
+ language = detect(output)
78
+ output = GoogleTranslator(source=language, target='ru').translate(output)
79
+ print(output)
80
+ return output
81
+
82
+ # css
83
+ css = """
84
+ footer {visibility: hidden !important;}
85
+ """
86
+
87
+
88
+ # ui
89
+ with gr.Blocks(css=css) as vui:
90
+ with gr.Tabs() as tabs:
91
+ with gr.Row():
92
+ with gr.Tab("Запрос", id='request v'):
93
+ with gr.Row():
94
+ with gr.Column(scale=3):
95
+ promt = gr.Textbox(show_label=True, label="Запрос")
96
+ with gr.Tab("Настройки", id='settingsv'):
97
+ with gr.Row():
98
+ with gr.Column(scale=3):
99
+ with gr.Row():
100
+ max_tokens = gr.Slider(show_label=True, label="Максимальное количество токенов", minimum=100, maximum=15000, value=5000, step=1)
101
+ with gr.Column():
102
+ text_button = gr.Button("Генерация", variant='primary', elem_id="generate")
103
+ with gr.Column(scale=2):
104
+ text_output = gr.Textbox(show_label=False, placeholder="Здравствуйте, я GPT-2! Чем я могу Вам помочь сегодня?")
105
+
106
+ text_button.click(generate, inputs=[promt, max_tokens], outputs=text_output)
107
+
108
+ #end
109
+ vui.queue(api_open=False).launch()