ak2603 commited on
Commit
3f9f45e
·
1 Parent(s): 328630e

testing hf space app.py summarizer

Browse files
Files changed (2) hide show
  1. app.py +95 -0
  2. requirements.txt +3 -0
app.py ADDED
@@ -0,0 +1,95 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # app.py
2
+ import streamlit as st
3
+ from transformers import pipeline
4
+
5
+ @st.cache_resource
6
+ def load_model(model_name):
7
+ if model_name == "mt5-small":
8
+ return pipeline("summarization", model="ak2603/mt5-small-synthetic-data-plus-translated")
9
+ # Add space for other models here
10
+ elif model_name == "Llama 3.2":
11
+ return None # Placeholder for future implementation
12
+ elif model_name == "Llama 7b Instruct":
13
+ return None # Placeholder for future implementation
14
+ else:
15
+ raise ValueError("Model not supported")
16
+
17
+ # Sample emails with reference summaries (for demonstration only)
18
+ SAMPLES = {
19
+ "Sample 1": (
20
+ """
21
+ Sehr geehrte Damen und Herren,
22
+ Ich bitte um die Kündigung meines Vertrages, da ich umziehe.
23
+ Vertragsnummer: 40887935006
24
+ Zählernummer: 17760731625925
25
+ Mit freundlichen Grüßen
26
+ Falk Rosemann, Truppring 7, 02044 Wernigerode
27
+ """,
28
+ "Der Kunde bittet um die Kündigung seines Vertrages aufgrund eines Umzugs und gibt die Vertrags- und Zählernummer an."
29
+ ),
30
+ "Sample 2": (
31
+ """
32
+ Die versprochene Rabattaktion wurde in meiner letzten Rechnung nicht berücksichtigt.
33
+ Mit freundlichen Grüßen
34
+ Prof. Vinko Caspar B.Eng., Jolanda-Pruschke-Platz 835, 42943 Neustadtner Waldnaab
35
+ """,
36
+ "Der Kunde erwähnt, dass die versprochene Rabattaktion in der letzten Rechnung nicht berücksichtigt wurde."
37
+ ),
38
+ "Sample 3": (
39
+ """
40
+ Sehr geehrte Damen und Herren,
41
+ Ich habe vor zwei Wochen eine Rechnung erhalten, die ich nicht nachvollziehen kann. Bitte erklären Sie die Details.
42
+ Herzliche Grüße
43
+ Kirstin Girschner-Meister, Oderwaldallee 510, 35412 Halberstadt
44
+ """,
45
+ "Der Kunde erwähnt, dass die versprochene Rabattaktion in der letzten Rechnung nicht berücksichtigt wurde und erwartet eine Überprüfung und Korrektur der Rechnung."
46
+
47
+ )
48
+ }
49
+
50
+ # UI Layout
51
+ st.title("🇩🇪 German Email Summarizer")
52
+ st.markdown("Fine-tuned summarization for German emails")
53
+
54
+ # Sidebar for model selection and sample emails
55
+ with st.sidebar:
56
+ st.header("⚙️ Settings")
57
+ model_choice = st.selectbox("Choose Model", ["mt5-small", "Llama 3.2", "Llama 7b Instruct"], index=0)
58
+ sample_choice = st.selectbox("Try Sample Email", ["Custom Input"] + list(SAMPLES.keys()))
59
+
60
+ # Load the selected model
61
+ summarizer = load_model(model_choice)
62
+
63
+ # Main interface
64
+ col1, col2 = st.columns(2)
65
+ with col1:
66
+ if sample_choice == "Custom Input":
67
+ input_text = st.text_area("Input Email", height=300, placeholder="Paste your email here...")
68
+ else:
69
+ input_text = st.text_area("Input Email", value=SAMPLES[sample_choice][0], height=300)
70
+
71
+ with col2:
72
+ if st.button("Generate Summary"):
73
+ if summarizer is None:
74
+ st.error("Selected model is not implemented yet.")
75
+ else:
76
+ with st.spinner("Generating summary..."):
77
+ try:
78
+ result = summarizer(
79
+ input_text,
80
+ max_length=150, # Fixed length for simplicity
81
+ do_sample=True,
82
+ repetition_penalty=1.5
83
+ )[0]['summary_text']
84
+
85
+ st.success("**Generated Summary:**")
86
+ st.write(result)
87
+
88
+ # Show sample comparison only if a sample is selected
89
+ if sample_choice != "Custom Input" and sample_choice in SAMPLES:
90
+ st.divider()
91
+ st.markdown(f"**Sample Reference Summary ({sample_choice}):**")
92
+ st.write(SAMPLES[sample_choice][1])
93
+
94
+ except Exception as e:
95
+ st.error(f"Error generating summary: {str(e)}")
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ streamlit
2
+ transformers
3
+ torch