Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import pipeline
|
| 3 |
+
|
| 4 |
+
# Lade Modelle von Hugging Face
|
| 5 |
+
llama_pipeline = pipeline("text-generation", model="meta-llama/Meta-Llama-3-8B")
|
| 6 |
+
finbert_pipeline = pipeline("text-classification", model="ProsusAI/finbert")
|
| 7 |
+
|
| 8 |
+
# Funktion für die Analyse
|
| 9 |
+
def analyze_financial_text(model_choice, text_input):
|
| 10 |
+
if not text_input:
|
| 11 |
+
return "Bitte gib einen Finanztext oder eine Frage ein."
|
| 12 |
+
|
| 13 |
+
if model_choice == "LLaMA 3 (Text-Generierung)":
|
| 14 |
+
response = llama_pipeline(text_input, max_length=200, do_sample=True)
|
| 15 |
+
return response[0]["generated_text"]
|
| 16 |
+
|
| 17 |
+
elif model_choice == "FinBERT (Sentiment-Analyse)":
|
| 18 |
+
response = finbert_pipeline(text_input)
|
| 19 |
+
return f"Ergebnis: {response[0]['label']} (Score: {response[0]['score']:.2f})"
|
| 20 |
+
|
| 21 |
+
return "Ungültige Auswahl."
|
| 22 |
+
|
| 23 |
+
# Gradio UI
|
| 24 |
+
with gr.Blocks() as demo:
|
| 25 |
+
gr.Markdown("# Finanz-Analyse mit Sprachmodellen (LLaMA 3 & FinBERT)")
|
| 26 |
+
|
| 27 |
+
model_choice = gr.Radio(
|
| 28 |
+
choices=["LLaMA 3 (Text-Generierung)", "FinBERT (Sentiment-Analyse)"],
|
| 29 |
+
label="Wähle ein Modell",
|
| 30 |
+
value="LLaMA 3 (Text-Generierung)"
|
| 31 |
+
)
|
| 32 |
+
|
| 33 |
+
text_input = gr.Textbox(label="Gib hier deinen Finanztext oder eine Frage ein", lines=5)
|
| 34 |
+
output = gr.Textbox(label="Modell-Response", lines=5)
|
| 35 |
+
|
| 36 |
+
analyze_button = gr.Button("Analysieren")
|
| 37 |
+
analyze_button.click(analyze_financial_text, inputs=[model_choice, text_input], outputs=output)
|
| 38 |
+
|
| 39 |
+
demo.launch()
|