Amna252003 commited on
Commit
3510ec1
·
verified ·
1 Parent(s): c86e71f

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +74 -17
index.html CHANGED
@@ -1,19 +1,76 @@
1
  <!doctype html>
2
  <html>
3
- <head>
4
- <meta charset="utf-8" />
5
- <meta name="viewport" content="width=device-width" />
6
- <title>My static Space</title>
7
- <link rel="stylesheet" href="style.css" />
8
- </head>
9
- <body>
10
- <div class="card">
11
- <h1>Welcome to your static Space!</h1>
12
- <p>You can modify this app directly by editing <i>index.html</i> in the Files and versions tab.</p>
13
- <p>
14
- Also don't forget to check the
15
- <a href="https://huggingface.co/docs/hub/spaces" target="_blank">Spaces documentation</a>.
16
- </p>
17
- </div>
18
- </body>
19
- </html>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  <!doctype html>
2
  <html>
3
+ <head>
4
+ <meta charset="utf-8" />
5
+ <meta name="viewport" content="width=device-width, initial-scale=1" />
6
+ <title>AI Paraphraser - Amna Shahzad</title>
7
+ <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@stlite/browser@0.85.1/build/stlite.css" />
8
+ <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@stlite/browser@0.85.1/build/style.css" />
9
+ </head>
10
+ <body>
11
+ <streamlit-app>
12
+ import json
13
+ import streamlit as st
14
+ from pyodide.code import run_js
15
+ from pyodide.ffi import to_js
16
+ from js import JSON, Object
17
+
18
+ # ONNX (browser) copy of google/flan-t5-small - T5 text-to-text model
19
+ MODEL = "Xenova/flan-t5-small"
20
+
21
+ st.set_page_config(page_title="AI Paraphraser", page_icon="✨", layout="wide")
22
+
23
+ # MANDATORY: Name and Student ID in the title
24
+ st.title("Amna Shahzad - Student ID: B04-0923-000008")
25
+ st.caption("CS4106 Mid-Term | AI Paraphraser (Text-to-Text with T5)")
26
+
27
+ if "gen" not in st.session_state:
28
+ msg = st.empty()
29
+ msg.info("Loading T5 model (first run only, please wait)...")
30
+ try:
31
+ mod = await run_js("import('https://cdn.jsdelivr.net/npm/@huggingface/transformers@3.8.1')")
32
+ st.session_state["gen"] = await mod.pipeline("text2text-generation", MODEL)
33
+ msg.empty()
34
+ except Exception as e:
35
+ msg.error(f"Could not load model: {e}")
36
+ st.stop()
37
+
38
+ gen = st.session_state["gen"]
39
+ st.success(f"Model loaded: {MODEL}")
40
+
41
+ text = st.text_area("Enter a sentence to paraphrase:", height=120, max_chars=1000)
42
+ creativity = st.slider("Creativity (temperature)", 0.3, 1.5, 0.8)
43
+
44
+ if st.button("Paraphrase"):
45
+ if not text.strip():
46
+ st.warning("Please type something first.")
47
+ elif len(text.split()) > 150:
48
+ st.error("Text too long - please keep it under 150 words.")
49
+ else:
50
+ try:
51
+ with st.spinner("Paraphrasing..."):
52
+ prompt = "Paraphrase this sentence in different words: " + text
53
+ opts = to_js({"max_new_tokens": 128, "do_sample": True,
54
+ "temperature": creativity, "top_p": 0.9},
55
+ dict_converter=Object.fromEntries)
56
+ raw = await gen(prompt, opts)
57
+ output = json.loads(JSON.stringify(raw))[0]["generated_text"]
58
+
59
+ col1, col2 = st.columns(2)
60
+ with col1:
61
+ st.subheader("📝 Original")
62
+ st.info(text)
63
+ st.caption(f"{len(text.split())} words")
64
+ with col2:
65
+ st.subheader("✨ Paraphrased")
66
+ st.success(output)
67
+ st.caption(f"{len(output.split())} words")
68
+
69
+ if output.strip().lower() == text.strip().lower():
70
+ st.warning("⚠️ Output is identical to input - try again or raise creativity.")
71
+ except Exception as e:
72
+ st.error(f"Something went wrong: {e}")
73
+ </streamlit-app>
74
+ <script type="module" src="https://cdn.jsdelivr.net/npm/@stlite/browser@0.85.1/build/stlite.js"></script>
75
+ </body>
76
+ </html>