Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -22,7 +22,6 @@ def load_model():
|
|
| 22 |
|
| 23 |
tokenizer = AutoTokenizer.from_pretrained(MODEL_PATH)
|
| 24 |
|
| 25 |
-
# Create pipeline
|
| 26 |
pipe = pipeline(
|
| 27 |
"text-generation",
|
| 28 |
model=model,
|
|
@@ -36,24 +35,38 @@ pipe = load_model()
|
|
| 36 |
|
| 37 |
@spaces.GPU(duration=110)
|
| 38 |
def generate_response(prompt, max_length=1024):
|
| 39 |
-
#
|
| 40 |
messages = [
|
| 41 |
-
{"role": "system", "content": "You are a helpful AI
|
| 42 |
{"role": "user", "content": prompt}
|
| 43 |
]
|
| 44 |
|
| 45 |
# Generate response using pipeline
|
| 46 |
outputs = pipe(messages, max_new_tokens=max_length)
|
| 47 |
|
| 48 |
-
# Extract the generated text
|
| 49 |
response = outputs[0]["generated_text"]
|
| 50 |
|
| 51 |
-
#
|
| 52 |
-
|
| 53 |
-
|
|
|
|
|
|
|
|
|
|
| 54 |
|
| 55 |
return response_only
|
| 56 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
demo = gr.Interface(
|
| 58 |
fn=generate_response,
|
| 59 |
inputs=[
|
|
@@ -69,7 +82,7 @@ demo = gr.Interface(
|
|
| 69 |
|
| 70 |
Model: [benhaotang/phi4-qwq-sky-t1]({MODEL_URL})""",
|
| 71 |
examples=[
|
| 72 |
-
[
|
| 73 |
]
|
| 74 |
)
|
| 75 |
|
|
|
|
| 22 |
|
| 23 |
tokenizer = AutoTokenizer.from_pretrained(MODEL_PATH)
|
| 24 |
|
|
|
|
| 25 |
pipe = pipeline(
|
| 26 |
"text-generation",
|
| 27 |
model=model,
|
|
|
|
| 35 |
|
| 36 |
@spaces.GPU(duration=110)
|
| 37 |
def generate_response(prompt, max_length=1024):
|
| 38 |
+
# Create messages with system prompt
|
| 39 |
messages = [
|
| 40 |
+
{"role": "system", "content": "You are a helpful AI assistant. You always think step by step."},
|
| 41 |
{"role": "user", "content": prompt}
|
| 42 |
]
|
| 43 |
|
| 44 |
# Generate response using pipeline
|
| 45 |
outputs = pipe(messages, max_new_tokens=max_length)
|
| 46 |
|
| 47 |
+
# Extract the generated text - outputs[0] is a dict with 'generated_text'
|
| 48 |
response = outputs[0]["generated_text"]
|
| 49 |
|
| 50 |
+
# Find the user's prompt in the response and get everything after it
|
| 51 |
+
try:
|
| 52 |
+
start_idx = response.find(prompt) + len(prompt)
|
| 53 |
+
response_only = response[start_idx:].strip()
|
| 54 |
+
except:
|
| 55 |
+
response_only = response # Fallback to full response if splitting fails
|
| 56 |
|
| 57 |
return response_only
|
| 58 |
|
| 59 |
+
# Example with proper line breaks
|
| 60 |
+
example_prompt = """For a scalar field theory with interaction Lagrangian $\mathcal{L}_{int} = g\phi^3 + \lambda\phi^4$:
|
| 61 |
+
|
| 62 |
+
1. Enumerate all possible 1-loop Feynman diagrams contributing to the scalar propagator
|
| 63 |
+
|
| 64 |
+
2. For each diagram, write down its loop contribution
|
| 65 |
+
|
| 66 |
+
3. Provide Mathematica code to calculate these loop amplitudes with dimensional regularization at $d=4-\epsilon$
|
| 67 |
+
|
| 68 |
+
Please explain your reasoning step by step."""
|
| 69 |
+
|
| 70 |
demo = gr.Interface(
|
| 71 |
fn=generate_response,
|
| 72 |
inputs=[
|
|
|
|
| 82 |
|
| 83 |
Model: [benhaotang/phi4-qwq-sky-t1]({MODEL_URL})""",
|
| 84 |
examples=[
|
| 85 |
+
[example_prompt] # Now using the formatted example
|
| 86 |
]
|
| 87 |
)
|
| 88 |
|