Spaces:
Running
Running
Upload Visualization.py
Browse files- pages/Visualization.py +53 -0
pages/Visualization.py
ADDED
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import requests
|
3 |
+
import io
|
4 |
+
from PIL import Image, UnidentifiedImageError
|
5 |
+
import os
|
6 |
+
import time
|
7 |
+
|
8 |
+
st.set_page_config(page_title="Student Assistant")
|
9 |
+
|
10 |
+
# API для генерации изображения
|
11 |
+
API_URL_img = "https://api-inference.huggingface.co/models/playgroundai/playground-v2-1024px-aesthetic"
|
12 |
+
headers = {"Authorization": os.getenv("api_token")}
|
13 |
+
|
14 |
+
# Функция генерации изображения
|
15 |
+
def generate_img(payload):
|
16 |
+
response = requests.post(API_URL_img, headers=headers, json=payload)
|
17 |
+
body = response.json()
|
18 |
+
if 'error' in body:
|
19 |
+
if 'estimated_time' in body:
|
20 |
+
time.sleep(body['estimated_time'])
|
21 |
+
else:
|
22 |
+
print(body)
|
23 |
+
return
|
24 |
+
generate_img(payload)
|
25 |
+
return response.content
|
26 |
+
|
27 |
+
|
28 |
+
st.markdown('# :female-student: Персональный помощник для студентов')
|
29 |
+
st.divider()
|
30 |
+
st.markdown("# :sparkles: Изучение английского языка через визуальное восприятие")
|
31 |
+
|
32 |
+
image_idea = st.text_input('Предложите свою тему для генерации изображения', value="Astronaut riding a horse")
|
33 |
+
image_gen__btn = st.button('Генерировать изображение')
|
34 |
+
if image_gen__btn:
|
35 |
+
with st.spinner('...'):
|
36 |
+
try:
|
37 |
+
image_bytes = generate_img({"inputs": image_idea})
|
38 |
+
image_raw = io.BytesIO(image_bytes)
|
39 |
+
st.success('Готово')
|
40 |
+
st.image(image_raw)
|
41 |
+
st.markdown('## Опишите фотографию на английском языке')
|
42 |
+
st.markdown('## План ответа поможет вам:')
|
43 |
+
st.markdown('+ the place;')
|
44 |
+
st.markdown('+ the action;')
|
45 |
+
st.markdown('+ the person’s appearance;')
|
46 |
+
st.markdown('+ whether you like the picture or not;')
|
47 |
+
st.markdown('+ why.')
|
48 |
+
st.markdown('Start with: “I’d like to describe this picture. The picture shows …” ')
|
49 |
+
except UnidentifiedImageError:
|
50 |
+
st.warning('This is a warning', icon="⚠️")
|
51 |
+
|
52 |
+
|
53 |
+
st.divider()
|