Spaces:
Paused
Paused
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 3 |
+
|
| 4 |
+
model_name = "DiscoResearch/DiscoLM_German_7b_v1"
|
| 5 |
+
model = AutoModelForCausalLM.from_pretrained(model_name, trust_remote_code=True)
|
| 6 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True)
|
| 7 |
+
|
| 8 |
+
def generate_answer(question):
|
| 9 |
+
inputs = tokenizer.encode("Question: " + question, return_tensors="pt")
|
| 10 |
+
outputs = model.generate(inputs, max_length=2000, num_return_sequences=1, do_sample=True)
|
| 11 |
+
answer = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 12 |
+
return answer
|
| 13 |
+
|
| 14 |
+
iface = gr.Interface(
|
| 15 |
+
fn=generate_answer,
|
| 16 |
+
inputs="text",
|
| 17 |
+
outputs="text",
|
| 18 |
+
title="The Art of Prompt Engineering",
|
| 19 |
+
description="Definiere deine Prompt, am besten auf Deutsch",
|
| 20 |
+
)
|
| 21 |
+
|
| 22 |
+
iface.launch(share=True) # Deploy the interface
|