Spaces:
Runtime error
Runtime error
visualize beam in output
Browse files- app.py +11 -2
- requirements.txt +3 -0
app.py
CHANGED
@@ -2,11 +2,20 @@ import os
|
|
2 |
import sys
|
3 |
import requests
|
4 |
import gradio as gr
|
|
|
|
|
|
|
|
|
5 |
|
6 |
def translate(input_txt,prefix,suffix,num_beams,topk,beta):
|
7 |
dictToSend = {'input':input_txt,'prefix':prefix,'suffix':suffix,'num_beams':num_beams,'alpha': (1-beta),'beta':beta,'topk':topk}
|
8 |
-
|
9 |
-
|
|
|
|
|
|
|
|
|
|
|
10 |
|
11 |
prefix= "<s>[INST] <<SYS>>\nYou are a professional translator from English to German. You translate the sentences to only Formal German even if the English sentence is Informal.\n<</SYS>>\nEnglish: "
|
12 |
#self.prefix = "Translate from English to German:\nEnglish: "
|
|
|
2 |
import sys
|
3 |
import requests
|
4 |
import gradio as gr
|
5 |
+
import json
|
6 |
+
import numpy as np
|
7 |
+
from io import BytesIO
|
8 |
+
from PIL import Image
|
9 |
|
10 |
def translate(input_txt,prefix,suffix,num_beams,topk,beta):
|
11 |
dictToSend = {'input':input_txt,'prefix':prefix,'suffix':suffix,'num_beams':num_beams,'alpha': (1-beta),'beta':beta,'topk':topk}
|
12 |
+
response = requests.post('https://d7bf-141-3-25-29.ngrok-free.app/generate', json=dictToSend)
|
13 |
+
response_data = json.loads(response.text)
|
14 |
+
processed_text = response_data.get('text')
|
15 |
+
processed_img = response_data.get('beam_img')
|
16 |
+
processed_image_array = np.array(processed_image_list, dtype=np.uint8)
|
17 |
+
processed_image = Image.fromarray(processed_image_array)
|
18 |
+
return processed_text, processed_image
|
19 |
|
20 |
prefix= "<s>[INST] <<SYS>>\nYou are a professional translator from English to German. You translate the sentences to only Formal German even if the English sentence is Informal.\n<</SYS>>\nEnglish: "
|
21 |
#self.prefix = "Translate from English to German:\nEnglish: "
|
requirements.txt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
requests
|
2 |
+
numpy
|
3 |
+
Pillow
|